package repository

import (
	"context"

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

type ListFilter struct {
	TenantID  string
	OwnerUID  string
	AccountID string
	Status    string
	StartAt   int64
	EndAt     int64
}

type ListResult struct {
	Items []entity.QueueItem
	Total int64
}

type Repository interface {
	EnsureIndexes(ctx context.Context) error
	Create(ctx context.Context, item *entity.QueueItem) error
	Get(ctx context.Context, tenantID, ownerUID, accountID, queueID string) (*entity.QueueItem, error)
	ListByIDs(ctx context.Context, tenantID, ownerUID string, ids []string) ([]entity.QueueItem, error)
	List(ctx context.Context, filter ListFilter, page, pageSize int) (*ListResult, error)
	ListDue(ctx context.Context, now int64, limit int) ([]entity.QueueItem, error)
	ListMissedCandidates(ctx context.Context, before int64, limit int) ([]entity.QueueItem, error)
	UpdateIfStatus(ctx context.Context, item *entity.QueueItem, allowed []string) (*entity.QueueItem, error)
	Update(ctx context.Context, item *entity.QueueItem) (*entity.QueueItem, error)
	CountByStatus(ctx context.Context, tenantID, ownerUID, accountID string, status string) (int64, error)
	CountPublishedSince(ctx context.Context, tenantID, ownerUID, accountID string, since int64) (int64, error)
	LastPublishedAt(ctx context.Context, tenantID, ownerUID, accountID string) (int64, error)
	Delete(ctx context.Context, tenantID, ownerUID, accountID, queueID string) error
	ListMediaIDsByAccount(ctx context.Context, tenantID, ownerUID, accountID string) ([]string, error)
	DeleteByAccount(ctx context.Context, tenantID, ownerUID, accountID string) (int64, error)
}
