package br

import (
	"context"
	"time"

	"github.com/tidbcloud/tidb-management-service/nextgen-global-service/domain/entity"
	"github.com/tidbcloud/tidb-management-service/nextgen-global-service/infra/repoimpl/schema"
	"github.com/tidbcloud/tidb-management-service/utilities/bizerr"
	"github.com/tidbcloud/tidb-management-service/utilities/pagination"
)

type QueryBackupsFilter struct {
	Ids               []uint64
	States            []schema.BackupState
	ClusterIds        []uint64
	SharedPoolIds     []uint64
	OrganizationIds   []uint64
	RegionIds         []string
	ServicePlans      []string
	TriggerTypes      []schema.BackupTriggerType
	AutoBackupTypes   []schema.AutoBackupType
	PauseOperationIds []string
	Purposes          []schema.BackupPurpose
	BackupTimeLte     *time.Time
	BackupTimeGte     *time.Time
	ExpirationTimeGt  *time.Time
	// ExcludeExpiredAutoBackupsAt hides expired automatic backups while keeping manual backups.
	ExcludeExpiredAutoBackupsAt *time.Time
	OrderBy                     *string
	Deleted                     *bool // if nil, query both deleted and not deleted backups, else query the backups with the same deleted state
}

type DeleteBackupsFilter struct {
	Ids               []uint64
	ClusterIds        []uint64
	OrganizationIds   []uint64
	TriggerTypes      []schema.BackupTriggerType
	ExpirationTimeLte *time.Time
}

//go:generate go run go.uber.org/mock/mockgen@latest -source=$GOFILE -package=mock_$GOPACKAGE -destination=./mock_$GOPACKAGE/mock_$GOFILE
type BackupRepo interface {
	Create(ctx context.Context, backup *entity.Backup) bizerr.BizError
	Save(ctx context.Context, backup *entity.Backup) bizerr.BizError
	Delete(ctx context.Context, filter *DeleteBackupsFilter) bizerr.BizError
	Get(ctx context.Context, backupId uint64) (*entity.Backup, bizerr.BizError)
	// Notice: these methods will return the deleted backups, unless you explicitly set the Deleted to false
	// If there two many backups, you should use pagination to query the backups
	UnscopedQuery(
		ctx context.Context,
		filter *QueryBackupsFilter,
		page *pagination.Page,
	) ([]*entity.Backup, bizerr.BizError)
	UnscopedCount(ctx context.Context, filter *QueryBackupsFilter) (int64, bizerr.BizError)
}
