package mysql

import (
	"context"
	"database/sql"
)

const (
	bizTypeRedPacketCreate = "red_packet_create"
	bizTypeRedPacketClaim  = "red_packet_claim"
	bizTypeRedPacketRefund = "red_packet_refund"

	eventTypeRedPacketCreated  = "WalletRedPacketCreated"
	eventTypeRedPacketClaimed  = "WalletRedPacketClaimed"
	eventTypeRedPacketRefunded = "WalletRedPacketRefunded"

	redPacketAllocationUnclaimed = "unclaimed"
	redPacketAllocationClaimed   = "claimed"
	redPacketAllocationExpired   = "expired"
)

type redPacketMetadata struct {
	AppCode           string `json:"app_code"`
	PacketID          string `json:"packet_id"`
	CommandID         string `json:"command_id"`
	SenderUserID      int64  `json:"sender_user_id"`
	RoomID            string `json:"room_id"`
	RegionID          int64  `json:"region_id"`
	RoomLocked        bool   `json:"room_locked"`
	OwnerUserID       int64  `json:"owner_user_id,omitempty"`
	PacketType        string `json:"packet_type"`
	TotalAmount       int64  `json:"total_amount"`
	PacketCount       int32  `json:"packet_count"`
	RemainingAmount   int64  `json:"remaining_amount"`
	RemainingCount    int32  `json:"remaining_count"`
	Status            string `json:"status"`
	OpenAtMS          int64  `json:"open_at_ms"`
	ExpiresAtMS       int64  `json:"expires_at_ms"`
	BalanceAfter      int64  `json:"balance_after"`
	WalletTransaction string `json:"wallet_transaction_id"`
	CreatedAtMS       int64  `json:"created_at_ms"`
}

type redPacketClaimMetadata struct {
	AppCode           string `json:"app_code"`
	ClaimID           string `json:"claim_id"`
	CommandID         string `json:"command_id"`
	PacketID          string `json:"packet_id"`
	UserID            int64  `json:"user_id"`
	Amount            int64  `json:"amount"`
	RoomID            string `json:"room_id"`
	RegionID          int64  `json:"region_id"`
	PacketType        string `json:"packet_type"`
	RemainingAmount   int64  `json:"remaining_amount"`
	RemainingCount    int32  `json:"remaining_count"`
	PacketStatus      string `json:"packet_status"`
	BalanceAfter      int64  `json:"balance_after"`
	WalletTransaction string `json:"wallet_transaction_id"`
	ClaimedAtMS       int64  `json:"claimed_at_ms"`
}

type redPacketRefundMetadata struct {
	AppCode           string `json:"app_code"`
	RefundID          string `json:"refund_id"`
	CommandID         string `json:"command_id"`
	PacketID          string `json:"packet_id"`
	SenderUserID      int64  `json:"sender_user_id"`
	RoomID            string `json:"room_id"`
	RegionID          int64  `json:"region_id"`
	PacketType        string `json:"packet_type"`
	RefundAmount      int64  `json:"refund_amount"`
	PacketStatus      string `json:"packet_status"`
	BalanceAfter      int64  `json:"balance_after"`
	WalletTransaction string `json:"wallet_transaction_id"`
	RefundedAtMS      int64  `json:"refunded_at_ms"`
}

type redPacketQuerier interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

type redPacketScanner interface {
	Scan(dest ...any) error
}
