package entity

import (
	"github.com/shopspring/decimal"
	"gorm.io/gorm"
	"time"
)

//go:generate ../../tools/bin/goqueryset -in entity.go

type Labels map[string]string
type MeteringUnits map[string]int32

const (
	UnitSkuType_COST     = "cost"
	UnitSkuType_METERING = "metering"
)

// gen:qs
type Unit struct {
	gorm.Model
	CostCenterOrgID uint   `gorm:"not null"`
	UnitKey         string `gorm:"type:varchar(128)"`
	SkuType         string `gorm:"type:varchar(64)"`
	Description     string `gorm:"type:varchar(255)"`
	Category        string `gorm:"type:varchar(255)"`
	Provider        string `gorm:"type:varchar(255)"`
	Region          string `gorm:"type:varchar(255)"`
	MeasureUnit     string `gorm:"type:varchar(255)"`
	MeteringUnits
	Version uint
}

const (
	MeasureStatus_INIT = "init"
	MeasureStatus_DONE = "done"
)

// gen:qs
type Measure struct {
	CostID         string          `gorm:"primarykey"`
	Unit           string          `gorm:"not null"`
	Cost           int             `gorm:"not null"`
	CostTime       time.Time       `gorm:"not null"`
	Labels         Labels          `gorm:"type:json"`
	CostPrice      decimal.Decimal `gorm:"type:decimal(30, 15)"`
	RawPrice       decimal.Decimal `gorm:"type:decimal(30, 15)"`
	Status         string          `gorm:"type:varchar(64)"`
	ConsumedSource string          `gorm:"not null"`
	Type           string          `gorm:"not null;default:'raw'"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
	Internal       bool `gorm:"default:0"`
}

// gen:qs
type CostCenter struct {
	CostCenterOrgID uint   `gorm:"not null"`
	CostCenterName  string `gorm:"type:varchar(128)"`
	Description     string `gorm:"type:varchar(255)"`
	Status          string `gorm:"type:varchar(64)"`
}

var Models = []interface{}{
	&Unit{},
	&Measure{},
	&CostCenter{},
}

const (
	CostCenterStatus_NOT_STARTED = "not_started"
	CostCenterStatus_STARTED     = "started"
	CostCenterStatus_DONE        = "done"
)
