package repository

import (
	"context"

	"haixun-backend/internal/model/copy_draft/domain/entity"
)

type InboxFilter struct {
	TenantID   string
	OwnerUID   string
	PersonaID  string
	Status     string
	RangeStart int64
	RangeEnd   int64
	Page       int
	PageSize   int
}

type InboxListResult struct {
	Items []entity.CopyDraft
	Total int64
}

type Repository interface {
	EnsureIndexes(ctx context.Context) error
	Create(ctx context.Context, draft *entity.CopyDraft) error
	CreateMany(ctx context.Context, drafts []*entity.CopyDraft) error
	Get(ctx context.Context, tenantID, ownerUID, personaID, draftID string) (*entity.CopyDraft, error)
	Update(ctx context.Context, tenantID, ownerUID, personaID, draftID string, patch map[string]interface{}) (*entity.CopyDraft, error)
	Delete(ctx context.Context, tenantID, ownerUID, personaID, draftID string) error
	DeleteMany(ctx context.Context, tenantID, ownerUID, personaID, missionID, draftType string, draftIDs []string) (int64, error)
	DeleteByMissionAndType(ctx context.Context, tenantID, ownerUID, personaID, missionID, draftType string) error
	DeleteByMission(ctx context.Context, tenantID, ownerUID, personaID, missionID string) error
	List(ctx context.Context, tenantID, ownerUID, personaID string, limit int) ([]entity.CopyDraft, error)
	ListInbox(ctx context.Context, filter InboxFilter) (*InboxListResult, error)
	ListByMission(ctx context.Context, tenantID, ownerUID, personaID, missionID string, limit int) ([]entity.CopyDraft, error)
	ReplaceMissionMatrix(
		ctx context.Context,
		tenantID, ownerUID, personaID, missionID string,
		drafts []*entity.CopyDraft,
	) error
	// PruneOldestPendingBeyond deletes oldest idle pending drafts (no mission / queue / publish) beyond keep.
	PruneOldestPendingBeyond(ctx context.Context, tenantID, ownerUID, personaID string, keep int) (int64, error)
}
