syntax = "v1"

type (
	ThreadsAccountData {
		ID               string `json:"id"`
		DisplayName      string `json:"display_name,omitempty"`
		Username         string `json:"username,omitempty"`
		ThreadsUserID    string `json:"threads_user_id,omitempty"`
		PersonaID        string `json:"persona_id,omitempty"` // deprecated: persona is chosen per publish, not bound to account
		BrowserConnected bool   `json:"browser_connected"`
		ApiConnected       bool  `json:"api_connected"`
		APITokenExpiresAt  int64 `json:"api_token_expires_at,omitempty"`
		Status             string `json:"status"`
		CreateAt         int64  `json:"create_at"`
		UpdateAt         int64  `json:"update_at"`
	}

	ListThreadsAccountsData {
		List            []ThreadsAccountData `json:"list"`
		ActiveAccountID string               `json:"active_account_id"`
	}

	DeleteThreadsAccountData {
		DeletedID       string `json:"deleted_id"`
		ActiveAccountID string `json:"active_account_id,omitempty"`
		Message         string `json:"message"`
	}

	CreateThreadsAccountReq {
		DisplayName string `json:"display_name,optional"`
		Activate    *bool  `json:"activate,optional"`
	}

	UpdateThreadsAccountReq {
		DisplayName *string `json:"display_name,optional"`
		PersonaID   *string `json:"persona_id,optional"` // deprecated: use persona_id in publish payload instead
	}

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

	ThreadsAccountConnectionPrefs {
		SearchViaApi     bool   `json:"search_via_api"`
		SearchSourceMode string `json:"search_source_mode"`
		PublishViaApi    bool   `json:"publish_via_api"`
		DevMode          bool   `json:"dev_mode"`
		ScrapeReplies    bool   `json:"scrape_replies"`
		RepliesPerPost   int    `json:"replies_per_post"`
		PublishHeaded    bool   `json:"publish_headed"`
		PlaywrightDebug  bool   `json:"playwright_debug"`
	}

	ThreadsAccountConnectionData {
		AccountID        string                        `json:"account_id"`
		AccountName      string                        `json:"account_name"`
		Username         string                        `json:"username,omitempty"`
		BrowserConnected bool                          `json:"browser_connected"`
		ApiConnected     bool                          `json:"api_connected"`
		Prefs            ThreadsAccountConnectionPrefs `json:"prefs"`
	}

	UpdateThreadsAccountConnectionReq {
		SearchViaApi     *bool   `json:"search_via_api,optional"`
		SearchSourceMode *string `json:"search_source_mode,optional"`
		PublishViaApi    *bool   `json:"publish_via_api,optional"`
		DevMode          *bool   `json:"dev_mode,optional"`
		ScrapeReplies    *bool   `json:"scrape_replies,optional"`
		RepliesPerPost   *int    `json:"replies_per_post,optional"`
		PublishHeaded    *bool   `json:"publish_headed,optional"`
		PlaywrightDebug  *bool   `json:"playwright_debug,optional"`
	}

	ImportThreadsAccountSessionReq {
		StorageState string `json:"storageState" validate:"required"`
	}

	ImportThreadsAccountSessionData {
		Success   bool   `json:"success"`
		Valid     bool   `json:"valid"`
		Synced    bool   `json:"synced"`
		AccountID string `json:"account_id"`
		Username  string `json:"username,omitempty"`
		Message   string `json:"message"`
		UpdateAt  int64  `json:"update_at"`
	}

	ThreadsAccountAiSettingsData {
		AccountID         string            `json:"account_id"`
		Provider          string            `json:"provider"`
		Model             string            `json:"model"`
		ResearchProvider  string            `json:"research_provider,omitempty"`
		ResearchModel     string            `json:"research_model,omitempty"`
		ApiKeys           map[string]string `json:"api_keys"`
		ApiKeysConfigured map[string]interface{} `json:"api_keys_configured"`
	}

	UpdateThreadsAccountAiSettingsReq {
		Provider         *string           `json:"provider,optional"`
		Model            *string           `json:"model,optional"`
		ResearchProvider *string           `json:"research_provider,optional"`
		ResearchModel    *string           `json:"research_model,optional"`
		ApiKeys          map[string]string `json:"api_keys,optional"`
	}

	UpdateThreadsAccountHandlerReq {
		ThreadsAccountPath
		UpdateThreadsAccountReq
	}

	UpdateThreadsAccountConnectionHandlerReq {
		ThreadsAccountPath
		UpdateThreadsAccountConnectionReq
	}

	ImportThreadsAccountSessionHandlerReq {
		ThreadsAccountPath
		ImportThreadsAccountSessionReq
	}

	UpdateThreadsAccountAiSettingsHandlerReq {
		ThreadsAccountPath
		UpdateThreadsAccountAiSettingsReq
	}

	ThreadsAccountAiProviderPath {
		ID       string `path:"id" validate:"required"`
		Provider string `path:"provider" validate:"required,oneof=opencode-go xai"`
	}

	ListThreadsAccountAiProviderModelsReq {
		ApiKey string `json:"api_key,optional"` // 選填；未帶則用已儲存的 key
	}

	ThreadsAccountAiProviderModelsHandlerReq {
		ThreadsAccountAiProviderPath
		ListThreadsAccountAiProviderModelsReq
	}

	ThreadsAccountAiProviderModelsData {
		ID      string   `json:"id"`
		Label   string   `json:"label"`
		Models  []string `json:"models"`
		Streams bool     `json:"streams"`
		Error   string   `json:"error,optional"`
	}

	StartThreadsOAuthQuery {
		AccountID string `form:"account_id,optional"`
	}

	StartThreadsOAuthData {
		AuthorizeURL string `json:"authorize_url"`
		State        string `json:"state"`
		AccountID    string `json:"account_id"`
	}

	ThreadsOAuthCallbackQuery {
		Code             string `form:"code,optional"`
		State            string `form:"state,optional"`
		Error            string `form:"error,optional"`
		ErrorReason      string `form:"error_reason,optional"`
		ErrorDescription string `form:"error_description,optional"`
	}

	ThreadsOAuthLogItem {
		At        int64  `json:"at"`
		Level     string `json:"level"`
		Stage     string `json:"stage"`
		AccountID string `json:"account_id,omitempty"`
		Message   string `json:"message"`
	}

	ListThreadsOAuthLogsData {
		List []ThreadsOAuthLogItem `json:"list"`
	}

	ThreadsOAuthConfigData {
		RedirectURI     string `json:"redirect_uri"`
		SuccessRedirect string `json:"success_redirect"`
		Enabled         bool   `json:"enabled"`
		RequiresHTTPS   bool   `json:"requires_https"`
	}

	ThreadsAPISmokeTestItem {
		Scope   string `json:"scope"`
		Name    string `json:"name"`
		Status  string `json:"status"`
		Message string `json:"message"`
		Count   int    `json:"count"`
	}

	RunThreadsAPISmokeTestData {
		List    []ThreadsAPISmokeTestItem `json:"list"`
		Passed  int                       `json:"passed"`
		Failed  int                       `json:"failed"`
		Skipped int                       `json:"skipped"`
		Total   int                       `json:"total"`
	}

	RunThreadsAPIPlaygroundReq {
		Action        string `json:"action" validate:"required"`
		Query         string `json:"query,optional"`
		Username      string `json:"username,optional"`
		MediaID       string `json:"media_id,optional"`
		ReplyID       string `json:"reply_id,optional"`
		ReplyToID     string `json:"reply_to_id,optional"`
		Text          string `json:"text,optional"`
		Permalink     string `json:"permalink,optional"`
		HintText      string `json:"hint_text,optional"`
		SkipPrime     bool   `json:"skip_prime,optional"`
		LocationQuery string `json:"location_query,optional"`
		Limit         int    `json:"limit,optional"`
		Hide          bool   `json:"hide,optional"`
		SearchType    string `json:"search_type,optional"`
	}

	RunThreadsAPIPlaygroundHandlerReq {
		ThreadsAccountPath
		RunThreadsAPIPlaygroundReq
	}

	ThreadsAPIPlaygroundData {
		Action  string `json:"action"`
		Ok      bool   `json:"ok"`
		Message string `json:"message"`
		Data    string `json:"data,optional"`
	}

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

	ListThreadsPostPerformanceHandlerReq {
		ThreadsAccountPath
		ListThreadsPostPerformanceQuery
	}

	ThreadsPostMetricCapability {
		Scope     string   `json:"scope"`
		Name      string   `json:"name"`
		Metrics   []string `json:"metrics"`
		Trackable bool     `json:"trackable"`
		Note      string   `json:"note,optional"`
	}

	ThreadsInsightMetricItem {
		Name  string `json:"name"`
		Value int    `json:"value"`
	}

	ThreadsAccountInsightsBlock {
		Status  string                     `json:"status"`
		Message string                     `json:"message,optional"`
		Metrics []ThreadsInsightMetricItem `json:"metrics,optional"`
	}

	ThreadsPostPerformanceItem {
		MediaID         string `json:"media_id"`
		Text            string `json:"text,optional"`
		Permalink       string `json:"permalink,optional"`
		Timestamp       string `json:"timestamp,optional"`
		MediaType       string `json:"media_type,optional"`
		MediaURL        string `json:"media_url,optional"`
		ThumbnailURL    string `json:"thumbnail_url,optional"`
		TopicTag        string `json:"topic_tag,optional"`
		Shortcode       string `json:"shortcode,optional"`
		LikeCount       int    `json:"like_count"`
		ReplyCount      int    `json:"reply_count"`
		RepostCount     int    `json:"repost_count,optional"`
		QuoteCount      int    `json:"quote_count,optional"`
		Views           int    `json:"views,optional"`
		Shares          int    `json:"shares,optional"`
		InsightsStatus  string `json:"insights_status,optional"`
		InsightsMessage string `json:"insights_message,optional"`
	}

	ThreadsPostPerformanceData {
		AccountID        string                        `json:"account_id"`
		Username         string                        `json:"username,optional"`
		ThreadsUserID    string                        `json:"threads_user_id,optional"`
		FetchedAt        int64                         `json:"fetched_at"`
		Capabilities     []ThreadsPostMetricCapability `json:"capabilities"`
		AccountInsights  ThreadsAccountInsightsBlock   `json:"account_insights"`
		Posts            []ThreadsPostPerformanceItem  `json:"posts"`
	}

	PublishQueueItemPath {
		ID  string `path:"id" validate:"required"`
		QID string `path:"qid" validate:"required"`
	}

	ListPublishQueueQuery {
		Status   string `form:"status,optional"`
		Page     int    `form:"page,optional"`
		PageSize int    `form:"pageSize,optional"`
	}

	ListPublishQueueHandlerReq {
		ThreadsAccountPath
		ListPublishQueueQuery
	}

	CreatePublishQueueReq {
		Text        string `json:"text" validate:"required"`
		TopicTag    string `json:"topic_tag,optional"`
		ScheduledAt int64  `json:"scheduled_at,optional"`
	}

	CreatePublishQueueHandlerReq {
		ThreadsAccountPath
		CreatePublishQueueReq
	}

	PatchPublishQueueReq {
		Text        *string `json:"text,optional"`
		TopicTag    *string `json:"topic_tag,optional"`
		ScheduledAt *int64  `json:"scheduled_at,optional"`
	}

	PatchPublishQueueHandlerReq {
		PublishQueueItemPath
		PatchPublishQueueReq
	}

	PublishQueueItemData {
		ID           string `json:"id"`
		AccountID    string `json:"account_id"`
		PersonaID    string `json:"persona_id,omitempty"`
		CopyMissionID string `json:"copy_mission_id,omitempty"`
		CopyDraftID   string `json:"copy_draft_id,omitempty"`
		Text         string `json:"text"`
		TopicTag     string `json:"topic_tag,omitempty"`
		ScheduledAt  int64  `json:"scheduled_at"`
		Status       string `json:"status"`
		MediaID      string `json:"media_id,optional"`
		Permalink    string `json:"permalink,optional"`
		PublishedAt  int64  `json:"published_at,optional"`
		ErrorMessage string `json:"error_message,optional"`
		RetryCount   int    `json:"retry_count,omitempty"`
		LastAttemptAt int64  `json:"last_attempt_at,omitempty"`
		NextAttemptAt int64  `json:"next_attempt_at,omitempty"`
		MissedAt     int64  `json:"missed_at,omitempty"`
		PausedReason string `json:"paused_reason,omitempty"`
		CreateAt     int64  `json:"create_at"`
		UpdateAt     int64  `json:"update_at"`
	}

	PublishQueueListData {
		Pagination PaginationData         `json:"pagination"`
		List       []PublishQueueItemData `json:"list"`
	}

	ListThreadsPublishHealthQuery {
		Page     int `form:"page,optional"`
		PageSize int `form:"pageSize,optional"`
	}

	ListThreadsPublishHealthHandlerReq {
		ThreadsAccountPath
		ListThreadsPublishHealthQuery
	}

	ThreadsPublishHealthSummary {
		PendingScheduled int64 `json:"pending_scheduled"`
		FailedCount      int64 `json:"failed_count"`
		Published7d      int64 `json:"published_7d"`
		TotalLikes7d     int   `json:"total_likes_7d"`
		TotalReplies7d   int   `json:"total_replies_7d"`
	}

	ThreadsPublishHealthCheckpoint {
		Checkpoint  string `json:"checkpoint"`
		LikeCount   int    `json:"like_count"`
		ReplyCount  int    `json:"reply_count"`
		RepostCount int    `json:"repost_count"`
		QuoteCount  int    `json:"quote_count"`
		Views       int    `json:"views,optional"`
		CheckedAt   int64  `json:"checked_at"`
	}

	ThreadsPublishHealthItem {
		MediaID     string                           `json:"media_id"`
		Permalink   string                           `json:"permalink,optional"`
		Text        string                           `json:"text,optional"`
		PublishedAt int64                            `json:"published_at"`
		LikeCount   int                              `json:"like_count"`
		ReplyCount  int                              `json:"reply_count"`
		RepostCount int                              `json:"repost_count,optional"`
		QuoteCount  int                              `json:"quote_count,optional"`
		Views       int                              `json:"views,optional"`
		Shares      int                              `json:"shares,optional"`
		Checkpoints []ThreadsPublishHealthCheckpoint `json:"checkpoints"`
	}

	ThreadsPublishHealthData {
		Summary    ThreadsPublishHealthSummary `json:"summary"`
		Pagination PaginationData              `json:"pagination"`
		List       []ThreadsPublishHealthItem  `json:"list"`
	}

	PublishSlotData {
		Weekday int    `json:"weekday"`
		Time    string `json:"time"`
	}

	PublishSourceRefData {
		Type          string `json:"type"`
		PersonaID     string `json:"persona_id,omitempty"`
		CopyMissionID string `json:"copy_mission_id,omitempty"`
		ScanPostID    string `json:"scan_post_id,omitempty"`
		ManualSeed    string `json:"manual_seed,omitempty"`
	}

	PublishInventoryPolicyData {
		AccountID         string                 `json:"account_id"`
		Enabled           bool                   `json:"enabled"`
		TargetDailyCount  int                    `json:"target_daily_count"`
		LowStockThreshold int                    `json:"low_stock_threshold"`
		LookaheadDays     int                    `json:"lookahead_days"`
		Timezone          string                 `json:"timezone"`
		Slots             []PublishSlotData      `json:"slots"`
		SourceRefs        []PublishSourceRefData `json:"source_refs"`
		UpdateAt          int64                  `json:"update_at"`
	}

	UpsertPublishInventoryPolicyReq {
		Enabled           bool                   `json:"enabled"`
		TargetDailyCount  int                    `json:"target_daily_count,optional"`
		LowStockThreshold int                    `json:"low_stock_threshold,optional"`
		LookaheadDays     int                    `json:"lookahead_days,optional"`
		Timezone          string                 `json:"timezone,optional"`
		Slots             []PublishSlotData      `json:"slots,optional"`
		SourceRefs        []PublishSourceRefData `json:"source_refs,optional"`
	}

	UpsertPublishInventoryPolicyHandlerReq {
		ThreadsAccountPath
		UpsertPublishInventoryPolicyReq
	}

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

	StartPublishInventoryRefillJobHandlerReq {
		ThreadsAccountPath
		StartPublishInventoryRefillJobReq
	}

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

	PublishSlotInsightData {
		Weekday        int    `json:"weekday"`
		Time           string `json:"time"`
		AvgLikes1h     int    `json:"avg_likes_1h"`
		AvgReplies1h   int    `json:"avg_replies_1h"`
		AvgLikes24h    int    `json:"avg_likes_24h"`
		AvgReplies24h  int    `json:"avg_replies_24h"`
		AvgLikes7d     int    `json:"avg_likes_7d"`
		AvgReplies7d   int    `json:"avg_replies_7d"`
		SampleSize     int    `json:"sample_size"`
		Recommendation string `json:"recommendation"`
	}

	PublishSlotInsightsData {
		AccountID string                   `json:"account_id"`
		Timezone  string                   `json:"timezone"`
		Slots     []PublishSlotInsightData `json:"slots"`
	}

	PublishGuardPolicyData {
		AccountID                    string `json:"account_id"`
		Enabled                      bool   `json:"enabled"`
		MaxDailyPosts                int    `json:"max_daily_posts"`
		MinIntervalMinutes           int    `json:"min_interval_minutes"`
		ConsecutiveFailurePauseLimit int    `json:"consecutive_failure_pause_limit"`
		Paused                       bool   `json:"paused"`
		PausedReason                 string `json:"paused_reason,omitempty"`
		UpdateAt                     int64  `json:"update_at"`
	}

	UpsertPublishGuardPolicyReq {
		Enabled                      bool   `json:"enabled"`
		MaxDailyPosts                int    `json:"max_daily_posts,optional"`
		MinIntervalMinutes           int    `json:"min_interval_minutes,optional"`
		ConsecutiveFailurePauseLimit int    `json:"consecutive_failure_pause_limit,optional"`
		Paused                       *bool  `json:"paused,optional"`
		PausedReason                 string `json:"paused_reason,optional"`
	}

	UpsertPublishGuardPolicyHandlerReq {
		ThreadsAccountPath
		UpsertPublishGuardPolicyReq
	}

	PublishQueueEventData {
		ID        string `json:"id"`
		QueueID   string `json:"queue_id"`
		EventType string `json:"event_type"`
		FromStatus string `json:"from_status,omitempty"`
		ToStatus   string `json:"to_status,omitempty"`
		Message   string `json:"message,omitempty"`
		CreateAt  int64  `json:"create_at"`
	}

	PublishQueueEventsData {
		List []PublishQueueEventData `json:"list"`
	}

	PublishAlertData {
		Type      string `json:"type"`
		Severity  string `json:"severity"`
		Message   string `json:"message"`
		QueueID   string `json:"queue_id,omitempty"`
		AccountID string `json:"account_id"`
		CreateAt  int64  `json:"create_at"`
	}

	PublishAlertsData {
		List []PublishAlertData `json:"list"`
	}

	PublishQueueRangeQuery {
		StartAt int64  `form:"startAt,optional"`
		EndAt   int64  `form:"endAt,optional"`
		Status  string `form:"status,optional"`
	}

	PublishQueueRangeHandlerReq {
		ThreadsAccountPath
		PublishQueueRangeQuery
	}

	PublishDashboardAccountSummary {
		AccountID        string `json:"account_id"`
		AccountName      string `json:"account_name"`
		PendingScheduled int64  `json:"pending_scheduled"`
		FailedCount      int64  `json:"failed_count"`
		Published7d      int64  `json:"published_7d"`
		TotalLikes7d     int    `json:"total_likes_7d"`
		TotalReplies7d   int    `json:"total_replies_7d"`
		Paused           bool   `json:"paused"`
		BestSlot         string `json:"best_slot,omitempty"`
		LowSlot          string `json:"low_slot,omitempty"`
	}

	PublishDashboardSummaryData {
		List            []PublishDashboardAccountSummary `json:"list"`
		TotalPending    int64                            `json:"total_pending"`
		TotalFailed     int64                            `json:"total_failed"`
		TotalPublished7d int64                            `json:"total_published_7d"`
		TotalLikes7d    int                              `json:"total_likes_7d"`
		TotalReplies7d  int                              `json:"total_replies_7d"`
	}

	GenerateOwnPostReplyDraftReq {
		MediaID         string `json:"media_id"`
		PersonaID       string `json:"persona_id,optional"`
		ReplyToID       string `json:"reply_to_id,optional"`
		PostText        string `json:"post_text,optional"`
		ReplyText       string `json:"reply_text,optional"`
		ThreadPostText  string `json:"thread_post_text,optional"`
		ParentReplyText string `json:"parent_reply_text,optional"`
	}

	GenerateOwnPostReplyDraftHandlerReq {
		ThreadsAccountPath
		GenerateOwnPostReplyDraftReq
	}

	GenerateOwnPostReplyDraftData {
		Text string `json:"text"`
	}

	MentionInboxItemData {
		MediaID         string `json:"media_id"`
		AuthorUsername  string `json:"author_username,omitempty"`
		Text            string `json:"text,omitempty"`
		Permalink       string `json:"permalink,omitempty"`
		Shortcode       string `json:"shortcode,omitempty"`
		Timestamp       string `json:"timestamp,omitempty"`
		MediaType       string `json:"media_type,omitempty"`
		IsReply         bool   `json:"is_reply"`
		IsQuotePost     bool   `json:"is_quote_post"`
		HasReplies      bool   `json:"has_replies"`
		RootPostID      string `json:"root_post_id,omitempty"`
		ParentID        string `json:"parent_id,omitempty"`
		ThreadPostText  string `json:"thread_post_text,omitempty"`
		ParentReplyText string `json:"parent_reply_text,omitempty"`
		ReplyReady      bool   `json:"reply_ready"`
		ReplyReadyMsg   string `json:"reply_ready_msg,omitempty"`
		SyncedAt        int64  `json:"synced_at"`
	}

	SyncMentionInboxReq {
		Limit    int `json:"limit,optional"`
		MaxPages int `json:"max_pages,optional"`
	}

	SyncMentionInboxHandlerReq {
		ThreadsAccountPath
		SyncMentionInboxReq
	}

	SyncMentionInboxData {
		Synced int   `json:"synced"`
		Ready  int   `json:"ready"`
		Total  int64 `json:"total"`
	}

	ListMentionInboxQuery {
		Page     int `form:"page,optional"`
		PageSize int `form:"pageSize,optional"`
	}

	ListMentionInboxHandlerReq {
		ThreadsAccountPath
		ListMentionInboxQuery
	}

	ListMentionInboxData {
		List           []MentionInboxItemData `json:"list"`
		Pagination     PaginationData         `json:"pagination"`
		ReadyTotal     int64                  `json:"ready_total"`
		NewestSyncedAt int64                  `json:"newest_synced_at,omitempty"`
	}

	PublishMentionReplyReq {
		Text string `json:"text"`
	}

	PublishMentionReplyPath {
		ID      string `path:"id" validate:"required"`
		MediaID string `path:"media_id" validate:"required"`
	}

	PublishMentionReplyHandlerReq {
		PublishMentionReplyPath
		PublishMentionReplyReq
	}

	PublishMentionReplyData {
		MediaID   string `json:"media_id,omitempty"`
		Permalink string `json:"permalink,omitempty"`
	}

	GenerateOwnPostFormulaReq {
		MediaID     string `json:"media_id"`
		PersonaID   string `json:"persona_id,optional"`
		PostText    string `json:"post_text,optional"`
		TopicTag    string `json:"topic_tag,optional"`
		MediaType   string `json:"media_type,optional"`
		Timestamp   string `json:"timestamp,optional"`
		LikeCount   int    `json:"like_count,optional"`
		ReplyCount  int    `json:"reply_count,optional"`
		Views       int    `json:"views,optional"`
		RepostCount int    `json:"repost_count,optional"`
		QuoteCount  int    `json:"quote_count,optional"`
		Shares      int    `json:"shares,optional"`
		Force       bool   `json:"force,optional"`
	}

	GenerateOwnPostFormulaHandlerReq {
		ThreadsAccountPath
		GenerateOwnPostFormulaReq
	}

	OwnPostFormulaReviewData {
		MediaID         string   `json:"media_id"`
		ReviewedAt      int64    `json:"reviewed_at"`
		FromCache       bool     `json:"from_cache,omitempty"`
		Summary         string   `json:"summary"`
		Wins            []string `json:"wins"`
		Improvements    []string `json:"improvements"`
		Formula         string   `json:"formula"`
		PostTemplate    string   `json:"post_template"`
		HookPattern     string   `json:"hook_pattern"`
		Structure       string   `json:"structure"`
		ReplicationTips []string `json:"replication_tips"`
		Avoid           []string `json:"avoid"`
	}

	GenerateOwnPostFormulaData {
		OwnPostFormulaReviewData
	}

	ListOwnPostFormulasHandlerReq {
		ThreadsAccountPath
	}

	ListOwnPostFormulasData {
		List []OwnPostFormulaReviewData `json:"list"`
	}

	ThreadsDiagnosticsData {
		AccountID      string                 `json:"account_id"`
		CheckedAt      int64                  `json:"checked_at"`
		ApiConnected   bool                   `json:"api_connected"`
		TokenExpiresAt int64                  `json:"token_expires_at,omitempty"`
		Scopes         []string               `json:"scopes"`
		Items          []ThreadsAPISmokeTestItem `json:"items"`
		Message        string                 `json:"message"`
	}

	ContentFormulaSourceMetricsData {
		LikeCount   int `json:"like_count,omitempty"`
		ReplyCount  int `json:"reply_count,omitempty"`
		Views       int `json:"views,omitempty"`
		RepostCount int `json:"repost_count,omitempty"`
		QuoteCount  int `json:"quote_count,omitempty"`
		Shares      int `json:"shares,omitempty"`
	}

	ContentFormulaData {
		ID              string                           `json:"id"`
		AccountID       string                           `json:"account_id"`
		Label           string                           `json:"label"`
		SourceType      string                           `json:"source_type"`
		SourceRef       string                           `json:"source_ref,omitempty"`
		SourcePostText  string                           `json:"source_post_text,omitempty"`
		SourceAuthor    string                           `json:"source_author,omitempty"`
		SourcePermalink string                           `json:"source_permalink,omitempty"`
		SourceMetrics   *ContentFormulaSourceMetricsData `json:"source_metrics,omitempty"`
		Summary         string                           `json:"summary"`
		Wins            []string                         `json:"wins,omitempty"`
		Improvements    []string                         `json:"improvements,omitempty"`
		Formula         string                           `json:"formula"`
		PostTemplate    string                           `json:"post_template"`
		HookPattern     string                           `json:"hook_pattern"`
		Structure       string                           `json:"structure"`
		ReplicationTips []string                         `json:"replication_tips,omitempty"`
		Avoid           []string                         `json:"avoid,omitempty"`
		Tags            []string                         `json:"tags,omitempty"`
		CreateAt        int64                            `json:"create_at"`
		UpdateAt        int64                            `json:"update_at"`
	}

	ListContentFormulasReq {
		Page       int64  `form:"page,optional"`
		PageSize   int64  `form:"pageSize,optional"`
		SourceType string `form:"source_type,optional"`
		Tag        string `form:"tag,optional"`
	}

	ListContentFormulasHandlerReq {
		ThreadsAccountPath
		ListContentFormulasReq
	}

	ListContentFormulasData {
		Pagination PaginationData       `json:"pagination"`
		List       []ContentFormulaData `json:"list"`
	}

	ContentFormulaItemPath {
		ID        string `path:"id" validate:"required"`
		FormulaID string `path:"formulaId" validate:"required"`
	}

	GetContentFormulaHandlerReq {
		ContentFormulaItemPath
	}

	AnalyzeContentFormulaReq {
		SourceType    string `json:"source_type" validate:"required"`
		PersonaID     string `json:"persona_id,optional"`
		PostText      string `json:"post_text,optional"`
		MediaID       string `json:"media_id,optional"`
		ScanPostID    string `json:"scan_post_id,optional"`
		Keyword       string `json:"keyword,optional"`
		SaveLabel     string `json:"save_label,optional"`
		AuthorName    string `json:"author_name,optional"`
		Permalink     string `json:"permalink,optional"`
		LikeCount     int    `json:"like_count,optional"`
		ReplyCount    int    `json:"reply_count,optional"`
		Views         int    `json:"views,optional"`
		RepostCount   int    `json:"repost_count,optional"`
		QuoteCount    int    `json:"quote_count,optional"`
		Shares        int    `json:"shares,optional"`
		ForceRefresh  bool   `json:"force_refresh,optional"`
	}

	AnalyzeContentFormulaHandlerReq {
		ThreadsAccountPath
		AnalyzeContentFormulaReq
	}

	AnalyzeContentFormulaData {
		Formula ContentFormulaData `json:"formula"`
		Message string             `json:"message"`
	}

	SearchContentFormulaPostsReq {
		Keyword    string `json:"keyword" validate:"required"`
		SearchType string `json:"search_type,optional"`
		Limit      int    `json:"limit,optional"`
	}

	SearchContentFormulaPostsHandlerReq {
		ThreadsAccountPath
		SearchContentFormulaPostsReq
	}

	ContentFormulaSearchPostData {
		Text            string `json:"text"`
		Author          string `json:"author"`
		Permalink       string `json:"permalink,omitempty"`
		MediaID         string `json:"media_id,omitempty"`
		LikeCount       int    `json:"like_count"`
		ReplyCount      int    `json:"reply_count"`
		EngagementScore int    `json:"engagement_score"`
	}

	SearchContentFormulaPostsData {
		List    []ContentFormulaSearchPostData `json:"list"`
		Message string                         `json:"message"`
	}

	PatchContentFormulaReq {
		Label        *string  `json:"label,optional"`
		Formula      *string  `json:"formula,optional"`
		PostTemplate *string  `json:"post_template,optional"`
		HookPattern  *string  `json:"hook_pattern,optional"`
		Structure    *string  `json:"structure,optional"`
		Tags         []string `json:"tags,optional"`
	}

	PatchContentFormulaHandlerReq {
		ContentFormulaItemPath
		PatchContentFormulaReq
	}

	DeleteContentFormulaData {
		FormulaID string `json:"formula_id"`
		Message   string `json:"message"`
	}

	ImportOwnPostFormulaReq {
		MediaID string `json:"media_id" validate:"required"`
		Label   string `json:"label,optional"`
	}

	ImportOwnPostFormulaHandlerReq {
		ThreadsAccountPath
		ImportOwnPostFormulaReq
	}
)

@server(
	group:      threads_account
	prefix:     /api/v1/threads-accounts
	middleware: AuthJWT
	tags:       "ThreadsAccount"
	summary:    "Threads operating account endpoints. Requires Bearer JWT."
)
service gateway {
	@handler listThreadsAccounts
	get / returns (ListThreadsAccountsData)

	@handler createThreadsAccount
	post / (CreateThreadsAccountReq) returns (ThreadsAccountData)

	@handler getThreadsAccount
	get /:id (ThreadsAccountPath) returns (ThreadsAccountData)

	@handler updateThreadsAccount
	patch /:id (UpdateThreadsAccountHandlerReq) returns (ThreadsAccountData)

	@handler deleteThreadsAccount
	delete /:id (ThreadsAccountPath) returns (DeleteThreadsAccountData)

	@handler activateThreadsAccount
	post /:id/activate (ThreadsAccountPath)

	@handler getThreadsAccountConnection
	get /:id/connection (ThreadsAccountPath) returns (ThreadsAccountConnectionData)

	@handler updateThreadsAccountConnection
	patch /:id/connection (UpdateThreadsAccountConnectionHandlerReq) returns (ThreadsAccountConnectionData)

	@handler importThreadsAccountSession
	post /:id/session/import (ImportThreadsAccountSessionHandlerReq) returns (ImportThreadsAccountSessionData)

	@handler getThreadsAccountAiSettings
	get /:id/ai-settings (ThreadsAccountPath) returns (ThreadsAccountAiSettingsData)

	@handler updateThreadsAccountAiSettings
	put /:id/ai-settings (UpdateThreadsAccountAiSettingsHandlerReq) returns (ThreadsAccountAiSettingsData)

	@handler listThreadsAccountAiProviderModels
	post /:id/ai-settings/providers/:provider/models (ThreadsAccountAiProviderModelsHandlerReq) returns (ThreadsAccountAiProviderModelsData)

	@handler startThreadsOauth
	get /oauth/start (StartThreadsOAuthQuery) returns (StartThreadsOAuthData)

	@handler listThreadsOauthLogs
	get /oauth/logs returns (ListThreadsOAuthLogsData)

	@handler getThreadsOauthConfig
	get /oauth/config returns (ThreadsOAuthConfigData)

	@handler disconnectThreadsApi
	post /:id/api/disconnect (ThreadsAccountPath) returns (ThreadsAccountData)

	@handler runThreadsApiSmokeTest
	post /:id/api/smoke-test (ThreadsAccountPath) returns (RunThreadsAPISmokeTestData)

	@handler runThreadsApiPlayground
	post /:id/api/playground (RunThreadsAPIPlaygroundHandlerReq) returns (ThreadsAPIPlaygroundData)

	@handler listThreadsPostPerformance
	get /:id/post-performance (ListThreadsPostPerformanceHandlerReq) returns (ThreadsPostPerformanceData)

	@handler createPublishQueueItem
	post /:id/publish-queue (CreatePublishQueueHandlerReq) returns (PublishQueueItemData)

	@handler listPublishQueueItems
	get /:id/publish-queue (ListPublishQueueHandlerReq) returns (PublishQueueListData)

	@handler getPublishQueueItem
	get /:id/publish-queue/:qid (PublishQueueItemPath) returns (PublishQueueItemData)

	@handler patchPublishQueueItem
	patch /:id/publish-queue/:qid (PatchPublishQueueHandlerReq) returns (PublishQueueItemData)

	@handler cancelPublishQueueItem
	post /:id/publish-queue/:qid/cancel (PublishQueueItemPath) returns (PublishQueueItemData)

	@handler deletePublishQueueItem
	delete /:id/publish-queue/:qid (PublishQueueItemPath)

	@handler listThreadsPublishHealth
	get /:id/publish-health (ListThreadsPublishHealthHandlerReq) returns (ThreadsPublishHealthData)

	@handler getPublishInventoryPolicy
	get /:id/publish-inventory-policy (ThreadsAccountPath) returns (PublishInventoryPolicyData)

	@handler upsertPublishInventoryPolicy
	put /:id/publish-inventory-policy (UpsertPublishInventoryPolicyHandlerReq) returns (PublishInventoryPolicyData)

	@handler startPublishInventoryRefillJob
	post /:id/publish-inventory/refill-jobs (StartPublishInventoryRefillJobHandlerReq) returns (StartPublishInventoryRefillJobData)

	@handler getPublishSlotInsights
	get /:id/publish-slot-insights (ThreadsAccountPath) returns (PublishSlotInsightsData)

	@handler getPublishGuardPolicy
	get /:id/publish-guard-policy (ThreadsAccountPath) returns (PublishGuardPolicyData)

	@handler upsertPublishGuardPolicy
	put /:id/publish-guard-policy (UpsertPublishGuardPolicyHandlerReq) returns (PublishGuardPolicyData)

	@handler resumePublishGuard
	post /:id/publish-guard/resume (ThreadsAccountPath) returns (PublishGuardPolicyData)

	@handler retryPublishQueueItem
	post /:id/publish-queue/:qid/retry (PublishQueueItemPath) returns (PublishQueueItemData)

	@handler listPublishQueueEvents
	get /:id/publish-queue/:qid/events (PublishQueueItemPath) returns (PublishQueueEventsData)

	@handler listPublishAlerts
	get /:id/publish-alerts (ThreadsAccountPath) returns (PublishAlertsData)

	@handler listPublishQueueRange
	get /:id/publish-calendar (PublishQueueRangeHandlerReq) returns (PublishQueueListData)

	@handler getThreadsDiagnostics
	get /:id/diagnostics (ThreadsAccountPath) returns (ThreadsDiagnosticsData)

	@handler generateOwnPostReplyDraft
	post /:id/own-post-reply-draft (GenerateOwnPostReplyDraftHandlerReq) returns (GenerateOwnPostReplyDraftData)

	@handler syncMentionInbox
	post /:id/mention-inbox/sync (SyncMentionInboxHandlerReq) returns (SyncMentionInboxData)

	@handler listMentionInbox
	get /:id/mention-inbox (ListMentionInboxHandlerReq) returns (ListMentionInboxData)

	@handler publishMentionReply
	post /:id/mention-inbox/:media_id/reply (PublishMentionReplyHandlerReq) returns (PublishMentionReplyData)

	@handler generateOwnPostFormula
	post /:id/own-post-formula (GenerateOwnPostFormulaHandlerReq) returns (GenerateOwnPostFormulaData)

	@handler listOwnPostFormulas
	get /:id/own-post-formulas (ListOwnPostFormulasHandlerReq) returns (ListOwnPostFormulasData)

	@handler getPublishDashboardSummary
	get /publish-dashboard-summary returns (PublishDashboardSummaryData)

	@handler listContentFormulas
	get /:id/content-formulas (ListContentFormulasHandlerReq) returns (ListContentFormulasData)

	@handler getContentFormula
	get /:id/content-formulas/:formulaId (GetContentFormulaHandlerReq) returns (ContentFormulaData)

	@handler analyzeContentFormula
	post /:id/content-formulas/analyze (AnalyzeContentFormulaHandlerReq) returns (AnalyzeContentFormulaData)

	@handler searchContentFormulaPosts
	post /:id/content-formulas/search-posts (SearchContentFormulaPostsHandlerReq) returns (SearchContentFormulaPostsData)

	@handler patchContentFormula
	patch /:id/content-formulas/:formulaId (PatchContentFormulaHandlerReq) returns (ContentFormulaData)

	@handler deleteContentFormula
	delete /:id/content-formulas/:formulaId (GetContentFormulaHandlerReq) returns (DeleteContentFormulaData)

	@handler importOwnPostToContentFormula
	post /:id/content-formulas/import-own-post (ImportOwnPostFormulaHandlerReq) returns (AnalyzeContentFormulaData)
}

@server(
	group:      threads_account
	prefix:     /api/v1/threads-accounts
	tags:       "ThreadsAccount"
	summary:    "Threads OAuth callback (public redirect from Meta)."
)
service gateway {
	@handler threadsOauthCallback
	get /oauth/callback (ThreadsOAuthCallbackQuery)
}
