package models

import (
	"time"

	"github.com/shopspring/decimal"
)

type GetProjectsReq struct {
	Total int64            `json:"total,omitempty"`
	Items []GetProjectItem `json:"items,omitempty"`
}

type GetProjectItem struct {
	Id               string `json:"id,omitempty"`
	Org_id           string `json:"org_id,omitempty"`
	Name             string `json:"name,omitempty"`
	Cluster_count    int64  `json:"cluster_count,omitempty"`
	User_count       int64  `json:"user_count,omitempty"`
	Create_timestamp string `json:"create_timestamp,omitempty"`
}

type BillsExplorerQuery struct {
	BilledMonth string `json:"billedMonth"`
}
type BillsCosts struct {
	//The sum of services that the specified organization consumed in the period during this bill period. The value of this field is expressed in cents (100ths of one US Dollar).
	RunningTotal decimal.Decimal `json:"runningTotal" example:"100.99"`
	//Total amount of discounts applied to this bill. The value of this field is expressed in cents (100ths of one US Dollar).
	Discounts decimal.Decimal `json:"discounts" example:"10.88"`
	//The total credits held by the organization in this bill. The value of this field is expressed in cents (100ths of one US Dollar).
	Credits decimal.Decimal `json:"credits" example:"10.11"`
	//The total amount that the specified organization should pay toward this bill. The value of this field is expressed in cents (100ths of one US Dollar).
	//`total_cost` = `running_total` - `discounts` - `credits`.
	TotalCost decimal.Decimal `json:"totalCost" example:"80.00"`
}
type BillsOverview struct {
	//The month in which this bill is generated for the specified organization.
	BilledMonth string `json:"BilledMonth" example:"2023-09"`
	BillsCosts
}
type BillsProjects struct {
	//The name of a project in the specified organization.
	ProjectName string `json:"projectName" example:"prod-project"`
	BillsCosts
}
type BillsOtherName struct {
	OtherName string `json:"otherName" example:"Support Plan"`
	BillsCosts
}
type SummaryByProject struct {
	//The projects in the specified organization.
	Projects []BillsProjects `json:"projects"`
	//These charges occur not only within a project but also across the entire organization.
	OtherCharges []BillsOtherName `json:"otherCharges"`
}
type BillsServiceCosts struct {
	//The name of services provided by TiDB Cloud.
	ServiceName string `json:"serviceName" example:"TiDB Dedicated"`
	BillsCosts
	ServiceCosts []BillsServiceCosts
}

type BillsExplorer struct {
	//The overall information for a bill in the specified organization.
	BillsOverView BillsOverview `json:"overview"`
	//A breakdown of the bill by project.
	SummaryByProject SummaryByProject `json:"summaryByProject"`
	//A breakdown of the bill by service.
	BillsServiceCosts []BillsServiceCosts `json:"summaryByService"`
}

// struct for msp openapi
type MspBills struct {
	//The overall information for a bill in the specified organization.
	BillsOverView BillsOverview `json:"overview"`
	//A breakdown of the bill by service.
	BillsServiceCosts []BillsServiceCosts `json:"summaryByService"`
	//Month of bills happens to a specific MSP.
	SummaryByCustomer []SummaryByCustomer `json:"summaryByCustomer"`
}
type SummaryByCustomer struct {
	//The Organization ID of MSP
	CustomerID uint `json:"customerID"`
	//Month of bills happens to a specific MSP Customer.
	MspCustomerBills BillsExplorer `json:"mspCustomerBills"`
}
type MspCredit struct {
	//The code of a credit.
	CreditCode string `json:"creditCode"`
	//The status of a credit.
	Status string `json:"status"`
	//The service which a credit is applicable to.
	Services string `json:"services"`
	//The total amount of credit.
	Credit decimal.Decimal `json:"credit"`
	//The remaining amount of a credit.
	RemainingCredit decimal.Decimal `json:"remainingCredit"`
	//Effective start date of a credit.
	StartDate time.Time `json:"startDate"`
	//Expired date of a credit.
	ExpiryDate time.Time `json:"expiryDate"`
}
type UnitFilterSlim struct {
	FilterID    uint   `json:"filter_id"`
	TypeID      uint   `json:"type_id"` // this field is a deprecated
	Name        string `json:"name"`
	Description string `json:"description"`
	ParentID    uint   `json:"parent_id"`
	Internal    bool   `json:"-"`
	Priority    int    `json:"-"`
}
type UnitFilter struct {
	UnitFilterSlim
	General        bool              `json:"general"`
	Provider       string            `json:"provider"`
	Region         string            `json:"region"`
	Category       string            `json:"category"`
	Labels         map[string]string `json:"labels"`
	UnitKeyPattern string            `json:"unit_key_pattern"`
}
type CreditsPackage struct {
	CreditsPackageID    uint              `json:"credits_package_id"`
	CreditsCode         string            `json:"credits_code"`
	TenantID            uint              `json:"tenant_id"`
	Status              string            `json:"status"`
	StartDate           time.Time         `json:"start_date"`
	ClosedDate          *time.Time        `json:"closed_date"`
	ExpiredDate         time.Time         `json:"expired_date"`
	BindedPackageID     *uint             `json:"binded_package_id"`
	RemainingCredits    decimal.Decimal   `json:"remaining_credits"`
	TotalCredits        decimal.Decimal   `json:"total_credits"`
	Type                string            `json:"type"`
	Usage               string            `json:"usage"`
	ClosedReason        string            `json:"closed_reason"`
	Note                string            `json:"note"`
	BindTypes           []*UnitFilterSlim `json:"bind_types"`
	UnitFilters         []*UnitFilterSlim `json:"unit_filters"`
	DiscountEnabled     bool              `json:"discount_enabled"`
	UnitFiltersInternal []*UnitFilter     `json:"-"`
	Internal            bool              `json:"internal"`
}
type MspDiscount struct {
	//The code of a discount.
	DiscountCode string `json:"discountCode"`
	//The status of a discount.
	Status string `json:"status"`
	//the service which a discount is applicable to.
	Services string `json:"services"`
	//the percentage is deducted from the original price. For example, a 20% discount on a $100 item would result in a discounted price of $80.
	PercentageDiscount string `json:"percentageDiscount"`
	//The description of a discount.
	Description string `json:"description"`
	//Effective start date of a credit.
	StartDate time.Time `json:"startDate"`
	//Expired date of a credit.
	ExpiryDate time.Time `json:"expiryDate"`
}

type Discount struct {
	DiscountID            uint              `json:"discount_id"`
	DiscountSID           string            `json:"discount_sid"`
	TenantID              uint              `json:"tenant_id"`
	Value                 decimal.Decimal   `json:"discount"`
	UnitFilters           []*UnitFilterSlim `json:"unit_filters"`
	Status                string            `json:"status"`
	StartedAt             time.Time         `json:"started_at"`
	ExpiredAt             time.Time         `json:"expired_at"`
	ClosedAt              *time.Time        `json:"closed_at"`
	Code                  string            `json:"discount_code"`
	Description           string            `json:"description"`
	Usage                 string            `json:"usage"`
	Note                  string            `json:"note"`
	CreatedAt             string            `json:"-"`
	Version               uint              `json:"-"`
	UnitFiltersInternal   []*UnitFilter     `json:"-"`
	OldDiscountUniqueMark *uint             `json:"-"`
	Active                string            `json:"-"`
}
