package models

import "time"

// Withdraw types. GENERAL waits for an admin to approve before any money
// moves; INSTANT deducts TDS and the flat instant charge and pays out
// straight away.
const (
	WithdrawTypeGeneral = "GENERAL"
	WithdrawTypeInstant = "INSTANT"
)

// Withdraw request statuses. Pending/Processing are the two states that block
// a second request, and the strings match what was already stored on the
// table before the two-type split.
const (
	WithdrawStatusPending    = "Pending"
	WithdrawStatusProcessing = "Processing"
	WithdrawStatusApproved   = "Approved"
	WithdrawStatusPaid       = "Paid"
	WithdrawStatusRejected   = "Rejected"
	WithdrawStatusFailed     = "Failed"
)

// Payment methods, matching the UPI / Bank transfer tabs on the withdraw
// screen. Both resolve to the astrologer's saved astrologer_bank_accounts row.
const (
	PaymentMethodUPI  = "UPI"
	PaymentMethodBank = "BANK"
)

type WalletWithdrawRequest struct {
	ID             uint    `gorm:"primaryKey;autoIncrement" json:"id"`
	AstrologerID   uint    `gorm:"column:astrologerId;not null;index" json:"astrologerId"`
	WithdrawAmount float64 `gorm:"column:withdrawAmount"`
	WithdrawType   string  `gorm:"column:withdrawType"`
	Status         string  `gorm:"column:status"`

	ProcessedAt *time.Time `gorm:"column:processedAt"`
	Remarks     string     `gorm:"column:remarks"`

	PaymentMethod     string `gorm:"column:paymentMethod"`
	UPIID             string `gorm:"column:upiId"`
	AccountNumber     string `gorm:"column:accountNumber"`
	IFSCCode          string `gorm:"column:ifscCode"`
	AccountHolderName string `gorm:"column:accountHolderName"`

	// Saved account the payout details were copied from. The copy is kept as
	// well, because the astrologer can edit the saved row after raising the
	// request and the payout must go where it was approved to go.
	BankAccountID uint   `gorm:"column:bankAccountId"`
	BankName      string `gorm:"column:bankName"`

	// Breakdown as it stood when the request was raised. Stored rather than
	// recomputed: the systemflag rates can change afterwards, and the
	// astrologer is owed what the summary screen showed them.
	TDSPercent    float64 `gorm:"column:tdsPercent"`
	TDSAmount     float64 `gorm:"column:tdsAmount"`
	InstantCharge float64 `gorm:"column:instantCharge"`
	NetAmount     float64 `gorm:"column:netAmount"`

	RequestNo string `gorm:"column:requestNo"`

	IsActive  bool       `gorm:"column:isActive"`
	IsDelete  bool       `gorm:"column:isDelete"`
	CreatedAt *time.Time `gorm:"column:created_at;autoCreateTime" json:"createdAt"`
	UpdatedAt *time.Time `gorm:"column:updated_at;autoUpdateTime" json:"updatedAt"`
}

func (WalletWithdrawRequest) TableName() string {
	return "withdrawrequest"
}
