package repository

import (
	"context"

	"haixun-backend/internal/model/job/domain/entity"
	"haixun-backend/internal/model/job/domain/enum"
)

type RunListFilter struct {
	Scope    string
	ScopeID  string
	TenantID string
	OwnerUID string
	Statuses []enum.RunStatus
}

type RunRepository interface {
	EnsureIndexes(ctx context.Context) error
	Create(ctx context.Context, run *entity.Run) (*entity.Run, error)
	Update(ctx context.Context, run *entity.Run) (*entity.Run, error)
	UpdateIfStatus(ctx context.Context, run *entity.Run, allowed []enum.RunStatus) (*entity.Run, error)
	UpdateIfLocked(ctx context.Context, run *entity.Run, workerID string, allowed []enum.RunStatus) (*entity.Run, error)
	FindByID(ctx context.Context, id string) (*entity.Run, error)
	List(ctx context.Context, filter RunListFilter, offset, limit int64) ([]*entity.Run, int64, error)
	FindActiveByScope(ctx context.Context, templateType, scope, scopeID string) ([]*entity.Run, error)
	FindSucceededByDedupeKey(ctx context.Context, templateType, dedupeKey string) (*entity.Run, error)
	FindPendingDue(ctx context.Context, now int64, limit int64) ([]*entity.Run, error)
	FindCancelRequestedBefore(ctx context.Context, before int64, limit int64) ([]*entity.Run, error)
	FindRunningTimedOut(ctx context.Context, now int64, limit int64) ([]*entity.Run, error)
}
