package hostorg

import walletv1 "hyapp.local/api/proto/wallet/v1"

type coinSellerStockCreditResponse struct {
	TransactionID          string `json:"transactionId"`
	SellerUserID           int64  `json:"sellerUserId,string"`
	StockType              string `json:"stockType"`
	CoinAmount             int64  `json:"coinAmount"`
	PaidCurrencyCode       string `json:"paidCurrencyCode"`
	PaidAmountMicro        int64  `json:"paidAmountMicro"`
	CountsAsSellerRecharge bool   `json:"countsAsSellerRecharge"`
	BalanceAfter           int64  `json:"balanceAfter"`
	CreatedAtMS            int64  `json:"createdAtMs"`
}

type coinSellerStockDebitResponse struct {
	TransactionID          string `json:"transactionId"`
	SellerUserID           int64  `json:"sellerUserId,string"`
	StockType              string `json:"stockType"`
	CoinAmount             int64  `json:"coinAmount"`
	AvailableDelta         int64  `json:"availableDelta"`
	PaidCurrencyCode       string `json:"paidCurrencyCode"`
	PaidAmountMicro        int64  `json:"paidAmountMicro"`
	CountsAsSellerRecharge bool   `json:"countsAsSellerRecharge"`
	BalanceAfter           int64  `json:"balanceAfter"`
	CreatedAtMS            int64  `json:"createdAtMs"`
}

func coinSellerStockCreditFromProto(item *walletv1.AdminCreditCoinSellerStockResponse) coinSellerStockCreditResponse {
	if item == nil {
		return coinSellerStockCreditResponse{}
	}
	return coinSellerStockCreditResponse{
		TransactionID:          item.GetTransactionId(),
		SellerUserID:           item.GetSellerUserId(),
		StockType:              item.GetStockType(),
		CoinAmount:             item.GetCoinAmount(),
		PaidCurrencyCode:       item.GetPaidCurrencyCode(),
		PaidAmountMicro:        item.GetPaidAmountMicro(),
		CountsAsSellerRecharge: item.GetCountsAsSellerRecharge(),
		BalanceAfter:           item.GetBalanceAfter(),
		CreatedAtMS:            item.GetCreatedAtMs(),
	}
}

func coinSellerStockDebitFromProto(sellerUserID int64, coinAmount int64, item *walletv1.AdminCreditCoinSellerStockResponse) coinSellerStockDebitResponse {
	if item == nil {
		return coinSellerStockDebitResponse{SellerUserID: sellerUserID, CoinAmount: coinAmount, AvailableDelta: -coinAmount}
	}
	return coinSellerStockDebitResponse{
		TransactionID:          item.GetTransactionId(),
		SellerUserID:           sellerUserID,
		StockType:              item.GetStockType(),
		CoinAmount:             item.GetCoinAmount(),
		AvailableDelta:         item.GetCoinAmount(),
		PaidCurrencyCode:       item.GetPaidCurrencyCode(),
		PaidAmountMicro:        item.GetPaidAmountMicro(),
		CountsAsSellerRecharge: item.GetCountsAsSellerRecharge(),
		BalanceAfter:           item.GetBalanceAfter(),
		CreatedAtMS:            item.GetCreatedAtMs(),
	}
}
