syntax = "v1"

type (
	CopyResearchMapData {
		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"`
		SuggestedTags   []string `json:"suggested_tags,omitempty"`
		BenchmarkNotes  string   `json:"benchmark_notes,omitempty"`
	}

	PersonaData {
		ID              string              `json:"id"`
		DisplayName     string              `json:"display_name,omitempty"`
		Persona         string              `json:"persona,omitempty"`
		Brief           string              `json:"brief,omitempty"`
		StyleProfile    string              `json:"style_profile,omitempty"`
		StyleBenchmark  string              `json:"style_benchmark,omitempty"`
		SeedQuery       string              `json:"seed_query,omitempty"`
		CopyResearchMap CopyResearchMapData `json:"copy_research_map,omitempty"`
		CreateAt        int64               `json:"create_at"`
		UpdateAt        int64               `json:"update_at"`
	}

	ListPersonasData {
		List []PersonaData `json:"list"`
	}

	CreatePersonaReq {
		DisplayName string `json:"display_name,optional"`
	}

	PersonaPath {
		ID string `path:"id" validate:"required"`
	}

	UpdatePersonaReq {
		DisplayName    *string `json:"display_name,optional"`
		Persona        *string `json:"persona,optional"`
		Brief          *string `json:"brief,optional"`
		StyleProfile   *string `json:"style_profile,optional"`
		StyleBenchmark *string `json:"style_benchmark,optional"`
	}

	StartPersonaStyleAnalysisReq {
		BenchmarkUsername string `json:"benchmark_username" validate:"required"`
	}

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

	UpdatePersonaHandlerReq {
		PersonaPath
		UpdatePersonaReq
	}

	StartPersonaStyleAnalysisHandlerReq {
		PersonaPath
		StartPersonaStyleAnalysisReq
	}

	StartPersonaViralScanJobReq {
		Keywords []string `json:"keywords,optional"`
	}

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

	StartPersonaViralScanJobHandlerReq {
		PersonaPath
		StartPersonaViralScanJobReq
	}

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

	ViralScanPostData {
		ID              string          `json:"id"`
		SearchTag       string          `json:"search_tag"`
		Permalink       string          `json:"permalink"`
		Author          string          `json:"author"`
		Text            string          `json:"text"`
		LikeCount       int             `json:"like_count"`
		ReplyCount      int             `json:"reply_count"`
		EngagementScore int             `json:"engagement_score"`
		Source          string          `json:"source"`
		ScanJobID       string          `json:"scan_job_id"`
		Replies         []ScanReplyData `json:"replies,omitempty"`
		CreateAt        int64           `json:"create_at"`
	}

	ListPersonaViralScanPostsData {
		List  []ViralScanPostData `json:"list"`
		Total int                 `json:"total"`
	}

	ListPersonaViralScanPostsHandlerReq {
		PersonaPath
		ListPersonaViralScanPostsReq
	}

	CopyDraftData {
		ID            string   `json:"id"`
		PersonaID     string   `json:"persona_id"`
		CopyMissionID string   `json:"copy_mission_id,omitempty"`
		ScanPostID    string   `json:"scan_post_id,omitempty"`
		DraftType     string   `json:"draft_type"`
		SortOrder     int      `json:"sort_order,omitempty"`
		Text       string   `json:"text"`
		Angle      string   `json:"angle,omitempty"`
		Hook           string   `json:"hook,omitempty"`
		Rationale      string   `json:"rationale,omitempty"`
		ReferenceNotes string   `json:"reference_notes,omitempty"`
		Sources        []string `json:"sources,omitempty"`
		Status             string `json:"status,omitempty"`
		PublishedMediaID   string `json:"published_media_id,omitempty"`
		PublishedPermalink string `json:"published_permalink,omitempty"`
		PublishedAt        int64  `json:"published_at,omitempty"`
		CreateAt           int64  `json:"create_at"`
	}

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

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

	GeneratePersonaCopyDraftHandlerReq {
		PersonaPath
		GeneratePersonaCopyDraftReq
	}

	GeneratePersonaCopyDraftData {
		Draft   CopyDraftData `json:"draft"`
		Message string        `json:"message"`
	}

	CopyDraftPath {
		ID      string `path:"id" validate:"required"`
		DraftID string `path:"draftId" validate:"required"`
	}

	UpdateCopyDraftReq {
		Text   *string `json:"text,optional"`
		Hook   *string `json:"hook,optional"`
		Angle  *string `json:"angle,optional"`
		Status *string `json:"status,optional"`
	}

	UpdateCopyDraftHandlerReq {
		CopyDraftPath
		UpdateCopyDraftReq
	}

	PublishCopyDraftReq {
		Text    string `json:"text,optional"`
		Confirm bool   `json:"confirm"`
	}

	PublishCopyDraftHandlerReq {
		CopyDraftPath
		PublishCopyDraftReq
	}

	PublishCopyDraftData {
		DraftID   string `json:"draft_id"`
		MediaID   string `json:"media_id"`
		Permalink string `json:"permalink,omitempty"`
		Status    string `json:"status"`
		Message   string `json:"message"`
	}
)

@server(
	group:      persona
	prefix:     /api/v1/personas
	middleware: AuthJWT
	tags:       "Persona"
	summary:    "Reusable persona profiles with 8D style strategy. Requires Bearer JWT."
)
service gateway {
	@handler listPersonas
	get / returns (ListPersonasData)

	@handler createPersona
	post / (CreatePersonaReq) returns (PersonaData)

	@handler getPersona
	get /:id (PersonaPath) returns (PersonaData)

	@handler updatePersona
	patch /:id (UpdatePersonaHandlerReq) returns (PersonaData)

	@handler deletePersona
	delete /:id (PersonaPath)

	@handler startPersonaStyleAnalysis
	post /:id/style-analysis (StartPersonaStyleAnalysisHandlerReq) returns (StartPersonaStyleAnalysisData)

	@handler startPersonaViralScanJob
	post /:id/viral-scan-jobs (StartPersonaViralScanJobHandlerReq) returns (StartPersonaViralScanJobData)

	@handler listPersonaViralScanPosts
	get /:id/viral-scan-posts (ListPersonaViralScanPostsHandlerReq) returns (ListPersonaViralScanPostsData)

	@handler listPersonaCopyDrafts
	get /:id/copy-drafts (PersonaPath) returns (ListPersonaCopyDraftsData)

	@handler generatePersonaCopyDraft
	post /:id/copy-drafts/generate (GeneratePersonaCopyDraftHandlerReq) returns (GeneratePersonaCopyDraftData)

	@handler updatePersonaCopyDraft
	patch /:id/copy-drafts/:draftId (UpdateCopyDraftHandlerReq) returns (CopyDraftData)

	@handler publishPersonaCopyDraft
	post /:id/copy-drafts/:draftId/publish (PublishCopyDraftHandlerReq) returns (PublishCopyDraftData)
}