syntax = "v1"

type (
	CopySuggestedTagData {
		Tag          string `json:"tag"`
		Reason       string `json:"reason,omitempty"`
		SearchIntent string `json:"search_intent,omitempty"`
		SearchType   string `json:"search_type,omitempty"`
	}

	CopySimilarAccountData {
		Username        string   `json:"username"`
		Reason          string   `json:"reason,omitempty"`
		Source          string   `json:"source,omitempty"`
		MatchedSource   []string `json:"matched_source,omitempty"`
		Confidence      string   `json:"confidence,omitempty"`
		Status          string   `json:"status,omitempty"`
		TopicRelevance  float64  `json:"topic_relevance,omitempty"`
		LastSeenAt      int64    `json:"last_seen_at,omitempty"`
		ProfileUrl      string   `json:"profile_url,omitempty"`
		AuthorVerified  bool     `json:"author_verified,omitempty"`
		FollowerCount   int      `json:"follower_count,omitempty"`
		EngagementScore int      `json:"engagement_score,omitempty"`
		LikeCount       int      `json:"like_count,omitempty"`
		ReplyCount      int      `json:"reply_count,omitempty"`
		PostCount       int      `json:"post_count,omitempty"`
	}

	CopyAudienceSampleData {
		Username       string `json:"username"`
		SamplePostId   string `json:"sample_post_id,omitempty"`
		SampleText     string `json:"sample_text,omitempty"`
		ReplyLikeCount int    `json:"reply_like_count,omitempty"`
		Appearances    int    `json:"appearances,omitempty"`
		FirstSeenAt    int64  `json:"first_seen_at"`
		LastSeenAt     int64  `json:"last_seen_at,omitempty"`
		Status         string `json:"status,omitempty"`
	}

	CopyMissionResearchItemData {
		Title   string `json:"title,omitempty"`
		URL     string `json:"url,omitempty"`
		Snippet string `json:"snippet,omitempty"`
		Query   string `json:"query,omitempty"`
	}

	CopyMissionResearchMapData {
		AudienceSummary string                   `json:"audience_summary,omitempty"`
		ContentGoal     string                   `json:"content_goal,omitempty"`
		Questions       []string                 `json:"questions,omitempty"`
		Pillars         []string                 `json:"pillars,omitempty"`
		Exclusions      []string                 `json:"exclusions,omitempty"`
		KnowledgeItems  []string                 `json:"knowledge_items,omitempty"`
		SelectedKnowledgeItems []string          `json:"selected_knowledge_items,omitempty"`
		ResearchItems   []CopyMissionResearchItemData `json:"research_items,omitempty"`
		SuggestedTags   []CopySuggestedTagData   `json:"suggested_tags,omitempty"`
		SimilarAccounts []CopySimilarAccountData `json:"similar_accounts,omitempty"`
		AudienceSamples []CopyAudienceSampleData `json:"audience_samples,omitempty"`
		BenchmarkNotes  string                   `json:"benchmark_notes,omitempty"`
	}

	ExpandCopyMissionGraphHandlerReq {
		CopyMissionPath
		ExpandKnowledgeGraphReq
	}

	PatchCopyMissionGraphNodesHandlerReq {
		CopyMissionPath
		PatchKnowledgeGraphNodesReq
	}

	PatchSimilarAccountReq {
		Status string `json:"status"`
	}

	PatchAudienceSampleReq {
		Status string `json:"status"`
	}

	CopyMissionSimilarAccountPath {
		PersonaID string `path:"personaId" validate:"required"`
		ID        string `path:"id" validate:"required"`
		Username  string `path:"username" validate:"required"`
	}

	PatchSimilarAccountHandlerReq {
		CopyMissionSimilarAccountPath
		PatchSimilarAccountReq
	}

	PatchAudienceSampleHandlerReq {
		CopyMissionSimilarAccountPath
		PatchAudienceSampleReq
	}

	CopyMissionData {
		ID            string                    `json:"id"`
		PersonaID     string                    `json:"persona_id"`
		Label         string                    `json:"label,omitempty"`
		SeedQuery     string                    `json:"seed_query,omitempty"`
		Brief         string                    `json:"brief,omitempty"`
		ResearchMap   CopyMissionResearchMapData `json:"research_map,omitempty"`
		SelectedTags  []string                  `json:"selected_tags,omitempty"`
		LastScanJobID string                    `json:"last_scan_job_id,omitempty"`
		Status        string                    `json:"status,omitempty"`
		CreateAt      int64                     `json:"create_at"`
		UpdateAt      int64                     `json:"update_at"`
	}

	ListCopyMissionsData {
		List []CopyMissionData `json:"list"`
	}

	CreateCopyMissionReq {
		Label     string `json:"label" validate:"required"`
		SeedQuery string `json:"seed_query" validate:"required"`
		Brief     string `json:"brief" validate:"required"`
	}

	UpdateCopyMissionReq {
		Label           *string  `json:"label,optional"`
		SeedQuery       *string  `json:"seed_query,optional"`
		Brief           *string  `json:"brief,optional"`
		AudienceSummary *string  `json:"audience_summary,optional"`
		ContentGoal     *string  `json:"content_goal,optional"`
		Questions       []string `json:"questions,optional"`
		Pillars         []string `json:"pillars,optional"`
		Exclusions      []string `json:"exclusions,optional"`
		KnowledgeItems  []string `json:"knowledge_items,optional"`
		SelectedKnowledgeItems []string `json:"selected_knowledge_items,optional"`
		BenchmarkNotes  *string  `json:"benchmark_notes,optional"`
		SelectedTags    []string `json:"selected_tags,optional"`
		Status          *string  `json:"status,optional"`
	}

	CopyMissionScanScheduleData {
		ID        string `json:"id,omitempty"`
		PersonaID string `json:"persona_id"`
		MissionID string `json:"mission_id"`
		Cron      string `json:"cron"`
		Timezone  string `json:"timezone"`
		Enabled   bool   `json:"enabled"`
		NextRunAt int64  `json:"next_run_at,omitempty"`
		LastRunAt int64  `json:"last_run_at,omitempty"`
	}

	UpsertCopyMissionScanScheduleReq {
		Cron     string `json:"cron,optional"`
		Timezone string `json:"timezone,optional"`
		Enabled  bool   `json:"enabled"`
	}

	UpsertCopyMissionScanScheduleHandlerReq {
		CopyMissionPath
		UpsertCopyMissionScanScheduleReq
	}

	CopyMissionPath {
		PersonaID string `path:"personaId" validate:"required"`
		ID        string `path:"id" validate:"required"`
	}

	PersonaCopyMissionsPath {
		PersonaID string `path:"personaId" validate:"required"`
	}

	CopyMissionInspirationReq {
		Keyword string `json:"keyword,optional"`
	}

	CopyMissionInspirationHandlerReq {
		PersonaCopyMissionsPath
		CopyMissionInspirationReq
	}

	CreateCopyMissionHandlerReq {
		PersonaCopyMissionsPath
		CreateCopyMissionReq
	}

	UpdateCopyMissionHandlerReq {
		CopyMissionPath
		UpdateCopyMissionReq
	}

	StartCopyMissionAnalyzeJobData {
		JobID   string `json:"job_id"`
		Status  string `json:"status"`
		Message string `json:"message"`
	}

	StartCopyMissionScanJobData {
		JobID   string `json:"job_id"`
		Status  string `json:"status"`
		Message string `json:"message"`
	}

	StartCopyMissionMatrixJobReq {
		Count int `json:"count,optional"`
	}

	StartCopyMissionMatrixJobHandlerReq {
		CopyMissionPath
		StartCopyMissionMatrixJobReq
	}

	StartCopyMissionMatrixJobData {
		JobID   string `json:"job_id"`
		Status  string `json:"status"`
		Message string `json:"message"`
	}

	StartCopyMissionCopyDraftJobReq {
		ScanPostID string `json:"scan_post_id" validate:"required"`
	}

	StartCopyMissionCopyDraftJobHandlerReq {
		CopyMissionPath
		StartCopyMissionCopyDraftJobReq
	}

	StartCopyMissionCopyDraftJobData {
		JobID   string `json:"job_id"`
		Status  string `json:"status"`
		Message string `json:"message"`
	}

	ListCopyMissionScanPostsReq {
		Limit int `form:"limit,optional"`
	}

	ListCopyMissionScanPostsHandlerReq {
		CopyMissionPath
		ListCopyMissionScanPostsReq
	}

	GenerateCopyMissionMatrixReq {
		Count int `json:"count,optional"`
	}

	GenerateCopyMissionMatrixHandlerReq {
		CopyMissionPath
		GenerateCopyMissionMatrixReq
	}

	GenerateCopyMissionMatrixData {
		Drafts  []CopyDraftData `json:"drafts"`
		Message string          `json:"message"`
	}

	ListCopyMissionCopyDraftsData {
		List  []CopyDraftData `json:"list"`
		Total int             `json:"total"`
	}

	DeleteCopyMissionMatrixDraftsReq {
		DraftIDs []string `json:"draft_ids,optional"`
	}

	DeleteCopyMissionMatrixDraftsHandlerReq {
		CopyMissionPath
		DeleteCopyMissionMatrixDraftsReq
	}

	DeleteCopyMissionMatrixDraftsData {
		Deleted int    `json:"deleted"`
		Message string `json:"message"`
	}

	CopyMissionInspirationSourceData {
		Query   string `json:"query,omitempty"`
		Title   string `json:"title,omitempty"`
		Snippet string `json:"snippet,omitempty"`
		URL     string `json:"url,omitempty"`
	}

	CopyMissionInspirationData {
		Label         string                           `json:"label"`
		SeedQuery     string                           `json:"seed_query"`
		Brief         string                           `json:"brief"`
		TrendReason   string                           `json:"trend_reason,omitempty"`
		TrendKeywords []string                         `json:"trend_keywords,omitempty"`
		Sources       []CopyMissionInspirationSourceData `json:"sources,omitempty"`
		WebSearchUsed bool                             `json:"web_search_used"`
		Message       string                           `json:"message"`
	}
)

@server(
	group:      copy_mission
	prefix:     /api/v1/personas
	middleware: AuthJWT
	tags:       "CopyMission"
	summary:    "Copy ninja missions (Flow A). Requires Bearer JWT."
)
service gateway {
	@handler listCopyMissions
	get /:personaId/copy-missions (PersonaCopyMissionsPath) returns (ListCopyMissionsData)

	@handler inspireCopyMission
	post /:personaId/copy-mission-inspiration (CopyMissionInspirationHandlerReq) returns (CopyMissionInspirationData)

	@handler createCopyMission
	post /:personaId/copy-missions (CreateCopyMissionHandlerReq) returns (CopyMissionData)

	@handler getCopyMission
	get /:personaId/copy-missions/:id (CopyMissionPath) returns (CopyMissionData)

	@handler updateCopyMission
	patch /:personaId/copy-missions/:id (UpdateCopyMissionHandlerReq) returns (CopyMissionData)

	@handler deleteCopyMission
	delete /:personaId/copy-missions/:id (CopyMissionPath)

	@handler startCopyMissionAnalyzeJob
	post /:personaId/copy-missions/:id/analyze-jobs (CopyMissionPath) returns (StartCopyMissionAnalyzeJobData)

	@handler startCopyMissionScanJob
	post /:personaId/copy-missions/:id/scan-jobs (CopyMissionPath) returns (StartCopyMissionScanJobData)

	@handler listCopyMissionScanPosts
	get /:personaId/copy-missions/:id/scan-posts (ListCopyMissionScanPostsHandlerReq) returns (ListPersonaViralScanPostsData)

	@handler generateCopyMissionMatrix
	post /:personaId/copy-missions/:id/matrix-drafts (GenerateCopyMissionMatrixHandlerReq) returns (GenerateCopyMissionMatrixData)

	@handler startCopyMissionMatrixJob
	post /:personaId/copy-missions/:id/matrix-jobs (StartCopyMissionMatrixJobHandlerReq) returns (StartCopyMissionMatrixJobData)

	@handler startCopyMissionCopyDraftJob
	post /:personaId/copy-missions/:id/copy-draft-jobs (StartCopyMissionCopyDraftJobHandlerReq) returns (StartCopyMissionCopyDraftJobData)

	@handler listCopyMissionCopyDrafts
	get /:personaId/copy-missions/:id/copy-drafts (CopyMissionPath) returns (ListCopyMissionCopyDraftsData)

	@handler deleteCopyMissionMatrixDrafts
	post /:personaId/copy-missions/:id/matrix-drafts/delete (DeleteCopyMissionMatrixDraftsHandlerReq) returns (DeleteCopyMissionMatrixDraftsData)

	@handler getCopyMissionScanSchedule
	get /:personaId/copy-missions/:id/scan-schedule (CopyMissionPath) returns (CopyMissionScanScheduleData)

	@handler upsertCopyMissionScanSchedule
	put /:personaId/copy-missions/:id/scan-schedule (UpsertCopyMissionScanScheduleHandlerReq) returns (CopyMissionScanScheduleData)

	@handler patchCopyMissionSimilarAccount
	patch /:personaId/copy-missions/:id/similar-accounts/:username (PatchSimilarAccountHandlerReq) returns (CopyMissionData)

	@handler patchCopyMissionAudienceSample
	patch /:personaId/copy-missions/:id/audience-samples/:username (PatchAudienceSampleHandlerReq) returns (CopyMissionData)

	@handler expandCopyMissionGraph
	post /:personaId/copy-missions/:id/knowledge-graph/expand (ExpandCopyMissionGraphHandlerReq) returns (ExpandKnowledgeGraphData)

	@handler getCopyMissionGraph
	get /:personaId/copy-missions/:id/knowledge-graph (CopyMissionPath) returns (KnowledgeGraphData)

	@handler patchCopyMissionGraphNodes
	patch /:personaId/copy-missions/:id/knowledge-graph/nodes (PatchCopyMissionGraphNodesHandlerReq) returns (KnowledgeGraphData)
}
