package usecase

import (
	"context"

	"haixun-backend/internal/library/placement"
)

type ScanReplySummary struct {
	ExternalID string
	Author     string
	Text       string
	Permalink  string
	LikeCount  int
	PostedAt   string
}

type ScanPostSummary struct {
	ID                 string
	BrandID            string
	PersonaID          string
	CopyMissionID      string
	Flow               string
	GraphNodeID        string
	SearchTag          string
	QueryDimension     string
	ExternalID         string
	Permalink          string
	Author             string
	AuthorVerified     bool
	FollowerCount      int
	Text               string
	Priority           string
	LikeCount          int
	ReplyCount         int
	EngagementScore    int
	PlacementScore     int
	ProductFitScore    int
	SolvedByProduct    bool
	Source             string
	ScanJobID          string
	OutreachStatus     string
	PublishedReplyID   string
	PublishedPermalink string
	OutreachUpdateAt   int64
	PostedAt           string
	Replies            []ScanReplySummary
	CreateAt           int64
}

type ListRequest struct {
	TenantID      string
	OwnerUID      string
	BrandID       string
	TopicID       string
	Priority      string
	ProductFitMin int
	Recent7dOnly  bool
	Limit         int
}

type ReplaceRequest struct {
	TenantID  string
	OwnerUID  string
	BrandID   string
	TopicID   string
	GraphID   string
	ScanJobID string
	Posts     []placement.ScanCandidate
}

type ViralReplaceRequest struct {
	TenantID      string
	OwnerUID      string
	PersonaID     string
	CopyMissionID string
	ScanJobID     string
	Posts         []placement.ScanCandidate
}

type PersonaListRequest struct {
	TenantID      string
	OwnerUID      string
	PersonaID     string
	CopyMissionID string
	Limit         int
}

type UpdateOutreachRequest struct {
	TenantID           string
	OwnerUID           string
	BrandID            string
	PostID             string
	Status             string
	PublishedReplyID   string
	PublishedPermalink string
}

type CheckpointRequest struct {
	TenantID  string
	OwnerUID  string
	BrandID   string
	TopicID   string
	GraphID   string
	ScanJobID string
	Posts     []placement.ScanCandidate
}

type UseCase interface {
	ClearPlacementScan(ctx context.Context, tenantID, ownerUID, brandID, topicID string) error
	UpsertScanCheckpoint(ctx context.Context, req CheckpointRequest) (int, error)
	FinalizeScan(ctx context.Context, req ReplaceRequest) (int, error)
	ReplaceFromScan(ctx context.Context, req ReplaceRequest) (int, error)
	ReplaceFromViralScan(ctx context.Context, req ViralReplaceRequest) (int, error)
	ClearCopyMissionViralScan(ctx context.Context, tenantID, ownerUID, personaID, copyMissionID string) error
	Get(ctx context.Context, tenantID, ownerUID, brandID, postID string) (*ScanPostSummary, error)
	GetForPersona(ctx context.Context, tenantID, ownerUID, personaID, postID string) (*ScanPostSummary, error)
	UpdateOutreach(ctx context.Context, req UpdateOutreachRequest) (*ScanPostSummary, error)
	Delete(ctx context.Context, tenantID, ownerUID, brandID, topicID, postID string) error
	DeleteMany(ctx context.Context, tenantID, ownerUID, brandID, topicID string, postIDs []string) (int, error)
	List(ctx context.Context, req ListRequest) ([]ScanPostSummary, error)
	ListForPersona(ctx context.Context, req PersonaListRequest) ([]ScanPostSummary, error)
}
