package billing

import (
	"context"

	globalcommonv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/common/v1"
	"github.com/tidbcloud/tidb-management-service/utilities/bizerr"
)

//go:generate go run go.uber.org/mock/mockgen@latest -source=$GOFILE -package=mock_$GOPACKAGE -destination=./mock_$GOPACKAGE/mock_$GOFILE
type Client interface {
	GetRemainingPocPoints(ctx context.Context, tenantID uint64) (float64, bizerr.BizError)
	Measure(ctx context.Context, reports []*Report) bizerr.BizError
	CalcFee(ctx context.Context, reports []*Report) (map[string]*Charge, bizerr.BizError)
	BillingActionCheck(
		ctx context.Context,
		action Action,
		tenantID uint64,
		resource *Resource,
	) (*ActionCheckResult, bizerr.BizError)
}

type Report struct {
	CostID        string
	TenantID      uint64
	Sku           string
	Cost          int64
	CostTimeStamp int64
	Labels        map[string]string
}

type Charge struct {
	RawPrice float64
	Price    float64
}

const UnitFilterALL = "all"

type ProviderEnum string

const (
	Provider_All   ProviderEnum = UnitFilterALL
	Provider_AWS   ProviderEnum = "AWS"
	Provider_GCP   ProviderEnum = "GCP"
	Provider_Azure ProviderEnum = "AZURE"
)

var ProviderMap = map[globalcommonv1.CloudProvider_Name]ProviderEnum{
	globalcommonv1.CloudProvider_ALICLOUD: Provider_All,
	globalcommonv1.CloudProvider_AWS:      Provider_AWS,
	globalcommonv1.CloudProvider_GCP:      Provider_GCP,
	globalcommonv1.CloudProvider_AZURE:    Provider_Azure,
}

type ResourceType string

const (
	ResourceType_DedicatedCluster  ResourceType = "dedicated_cluster"
	ResourceType_DedicatedBackup   ResourceType = "dedicated_backup"
	ResourceType_ServerlessCluster ResourceType = "serverless_cluster"
)

type Resource struct {
	Type       ResourceType  `json:"type"`
	InstanceID *string       `json:"instance_id"`
	Region     *string       `json:"region"`
	Provider   *ProviderEnum `json:"provider"`
	IsFree     bool          `json:"is_free"`
}

type Action string

const Action_Create Action = "add"
const Action_Delete Action = "remove"
const Action_Scaleup Action = "expand"
const Action_Scaledown Action = "shrink"

type ActionCheckResult struct {
	Pass   bool    `json:"pass"`
	Reason *string `json:"reason"`
}
