package ledger

import (
	"strings"
)

// CoinSellerTransferCommand 是币商给玩家转普通金币的账务命令。
type CoinSellerTransferCommand struct {
	AppCode         string
	CommandID       string
	SellerUserID    int64
	TargetUserID    int64
	TargetCountryID int64
	SellerRegionID  int64
	TargetRegionID  int64
	Amount          int64
	Reason          string
}

// CoinSellerTransferReceipt 是币商转账完成后的稳定回执。
type CoinSellerTransferReceipt struct {
	TransactionID              string
	SellerBalanceAfter         int64
	TargetBalanceAfter         int64
	Amount                     int64
	RechargeSequence           int64
	RechargeUSDMinor           int64
	RechargeCurrencyCode       string
	RechargePolicyID           int64
	RechargePolicyVersion      string
	RechargePolicyCoinAmount   int64
	RechargePolicyUSDMinorUnit int64
}

// CoinSellerSubTransferCommand 是父币商向直属子币商转移 COIN_SELLER_COIN 库存的账务命令。
type CoinSellerSubTransferCommand struct {
	AppCode      string
	CommandID    string
	ParentUserID int64
	ChildUserID  int64
	RegionID     int64
	Amount       int64
	Reason       string
}

// CoinSellerSubTransferReceipt 返回父子币商库存转账后的双边余额。
type CoinSellerSubTransferReceipt struct {
	TransactionID      string
	ParentUserID       int64
	ChildUserID        int64
	ParentBalanceAfter int64
	ChildBalanceAfter  int64
	Amount             int64
	CreatedAtMS        int64
}

// CoinSellerSalaryExchangeRateTier 是工资转给币商时按区域和美元金额匹配的金币兑换比例。
type CoinSellerSalaryExchangeRateTier struct {
	RegionID    int64
	MinUSDMinor int64
	MaxUSDMinor int64
	CoinPerUSD  int64
	Status      string
	SortOrder   int
	UpdatedAtMS int64
}

// SalaryExchangeCommand 是用户把某个身份工资美元钱包兑换为自己普通金币的账务命令。
type SalaryExchangeCommand struct {
	AppCode         string
	CommandID       string
	UserID          int64
	SalaryAssetType string
	SalaryUSDMinor  int64
	Reason          string
}

// SalaryExchangeReceipt 返回工资扣减和普通金币入账后的双边余额。
type SalaryExchangeReceipt struct {
	TransactionID      string
	UserID             int64
	SalaryAssetType    string
	SalaryBalanceAfter int64
	CoinBalanceAfter   int64
	SalaryUSDMinor     int64
	CoinAmount         int64
	CoinPerUSD         int64
	CreatedAtMS        int64
}

// SalaryTransferToCoinSellerCommand 是用户把某个身份工资美元钱包转给同区域币商专用金币库存的账务命令。
type SalaryTransferToCoinSellerCommand struct {
	AppCode         string
	CommandID       string
	SourceUserID    int64
	SellerUserID    int64
	SalaryAssetType string
	SalaryUSDMinor  int64
	RegionID        int64
	Reason          string
}

// SalaryTransferToCoinSellerReceipt 返回工资扣减和币商库存入账后的双边余额与命中的区间。
type SalaryTransferToCoinSellerReceipt struct {
	TransactionID            string
	SourceUserID             int64
	SellerUserID             int64
	SalaryAssetType          string
	SourceSalaryBalanceAfter int64
	SellerBalanceAfter       int64
	SalaryUSDMinor           int64
	CoinAmount               int64
	CoinPerUSD               int64
	RateMinUSDMinor          int64
	RateMaxUSDMinor          int64
	CreatedAtMS              int64
}

// CoinSellerStockCreditCommand 是后台给币商专用金币库存入账的最小账务命令。
type CoinSellerStockCreditCommand struct {
	AppCode          string
	CommandID        string
	SellerUserID     int64
	SellerCountryID  int64
	SellerRegionID   int64
	StockType        string
	CoinAmount       int64
	PaidCurrencyCode string
	PaidAmountMicro  int64
	PaymentRef       string
	EvidenceRef      string
	OperatorUserID   int64
	Reason           string
}

// CoinSellerStockCreditReceipt 是币商库存入账成功后的稳定回执。
type CoinSellerStockCreditReceipt struct {
	TransactionID          string
	SellerUserID           int64
	SellerCountryID        int64
	SellerRegionID         int64
	StockType              string
	CoinAmount             int64
	PaidCurrencyCode       string
	PaidAmountMicro        int64
	CountsAsSellerRecharge bool
	BalanceAfter           int64
	CreatedAtMS            int64
}

func NormalizeCoinSellerStockType(stockType string) string {
	switch strings.ToLower(strings.TrimSpace(stockType)) {
	case StockTypeUSDTPurchase:
		return StockTypeUSDTPurchase
	case StockTypeUSDTDeduction:
		return StockTypeUSDTDeduction
	case StockTypeCoinCompensation:
		return StockTypeCoinCompensation
	default:
		return ""
	}
}
