package usecase

import "context"

type QueueItemSummary struct {
	ID            string
	AccountID     string
	PersonaID     string
	CopyMissionID string
	CopyDraftID   string
	Text          string
	TopicTag      string
	ScheduledAt   int64
	Status        string
	MediaID       string
	Permalink     string
	PublishedAt   int64
	ErrorMessage  string
	RetryCount    int
	LastAttemptAt int64
	NextAttemptAt int64
	MissedAt      int64
	PausedReason  string
	CreateAt      int64
	UpdateAt      int64
}

type CreateRequest struct {
	TenantID      string
	OwnerUID      string
	AccountID     string
	PersonaID     string
	CopyMissionID string
	CopyDraftID   string
	Text          string
	TopicTag      string
	ScheduledAt   int64
}

type UpdateRequest struct {
	TenantID    string
	OwnerUID    string
	AccountID   string
	QueueID     string
	Text        *string
	TopicTag    *string
	ScheduledAt *int64
}

type ListRequest struct {
	TenantID  string
	OwnerUID  string
	AccountID string
	Status    string
	Page      int
	PageSize  int
}

type RangeRequest struct {
	TenantID  string
	OwnerUID  string
	AccountID string
	Status    string
	StartAt   int64
	EndAt     int64
	Page      int
	PageSize  int
}

type ListResult struct {
	Items      []QueueItemSummary
	Total      int64
	Page       int
	PageSize   int
	TotalPages int
}

type PublishHealthSummary struct {
	PendingScheduled int64
	FailedCount      int64
	Published7d      int64
	TotalLikes7d     int
	TotalReplies7d   int
}

type PublishHealthCheckpoint struct {
	Checkpoint  string
	LikeCount   int
	ReplyCount  int
	RepostCount int
	QuoteCount  int
	Views       int
	CheckedAt   int64
}

type PublishHealthItem struct {
	MediaID     string
	Permalink   string
	Text        string
	PublishedAt int64
	LikeCount   int
	ReplyCount  int
	RepostCount int
	QuoteCount  int
	Views       int
	Shares      int
	Checkpoints []PublishHealthCheckpoint
}

type PublishHealthResult struct {
	Summary    PublishHealthSummary
	Items      []PublishHealthItem
	Total      int64
	Page       int
	PageSize   int
	TotalPages int
}

type RecordPublishedRequest struct {
	TenantID      string
	OwnerUID      string
	AccountID     string
	PersonaID     string
	CopyMissionID string
	CopyDraftID   string
	Text          string
	TopicTag      string
	MediaID       string
	Permalink     string
	PublishedAt   int64
}

type SlotInsight struct {
	Weekday        int
	Time           string
	AvgLikes1h     int
	AvgReplies1h   int
	AvgLikes24h    int
	AvgReplies24h  int
	AvgLikes7d     int
	AvgReplies7d   int
	SampleSize     int
	Recommendation string
}

type Alert struct {
	Type      string
	Severity  string
	Message   string
	QueueID   string
	AccountID string
	CreateAt  int64
}

type UseCase interface {
	Create(ctx context.Context, req CreateRequest) (*QueueItemSummary, error)
	RecordPublished(ctx context.Context, req RecordPublishedRequest) (*QueueItemSummary, error)
	Get(ctx context.Context, tenantID, ownerUID, accountID, queueID string) (*QueueItemSummary, error)
	ListByIDs(ctx context.Context, tenantID, ownerUID string, ids []string) ([]QueueItemSummary, error)
	List(ctx context.Context, req ListRequest) (*ListResult, error)
	ListRange(ctx context.Context, req RangeRequest) (*ListResult, error)
	Update(ctx context.Context, req UpdateRequest) (*QueueItemSummary, error)
	Cancel(ctx context.Context, tenantID, ownerUID, accountID, queueID string) (*QueueItemSummary, error)
	Retry(ctx context.Context, tenantID, ownerUID, accountID, queueID string) (*QueueItemSummary, error)
	Delete(ctx context.Context, tenantID, ownerUID, accountID, queueID string) error
	DispatchDue(ctx context.Context, limit int) (int, error)
	MarkMissed(ctx context.Context, graceNs int64, limit int) (int, error)
	ListAlerts(ctx context.Context, tenantID, ownerUID, accountID string) ([]Alert, error)
	ListSlotInsights(ctx context.Context, tenantID, ownerUID, accountID, timezone string) ([]SlotInsight, error)
	ListPublishHealth(ctx context.Context, tenantID, ownerUID, accountID string, page, pageSize int) (*PublishHealthResult, error)
}
