package square

import "context"

type CreatePaymentReq struct {
	Amount         int64  // in pence (GBP cents)
	Currency       string // "GBP"
	SourceID       string // card token or "cnon:xxx" nonce
	IdempotencyKey string
	ReferenceID    string // booking ID
	Note           string
}

type CreateCheckoutReq struct {
	Amount         int64
	Currency       string
	IdempotencyKey string
	ReferenceID    string
	TipEnabled     bool
}

type RefundPaymentReq struct {
	PaymentID      string
	Amount         int64 // in pence, 0 = full refund
	IdempotencyKey string
	Reason         string
}

type PaymentResult struct {
	ID          string
	Status      string // "COMPLETED", "FAILED", "PENDING"
	Amount      int64
	CardBrand   string
	CardLast4   string
	TipAmount   int64
	ReceiptURL  string
	SquarePayID string // Square's payment ID
	Fees        int64  // processing fee in pence
}

type CheckoutResult struct {
	ID     string
	Status string // "PENDING", "COMPLETED", "FAILED"
}

type CardOnFile struct {
	ID          string
	CardID      string // Square's card-on-file token
	Brand       string
	Last4       string
	ExpMonth    int
	ExpYear     int
	Fingerprint string
	IsDefault   bool
}

type RefundResult struct {
	ID     string
	Status string
	Amount int64
}

type SquareClient interface {
	CreatePayment(ctx context.Context, req CreatePaymentReq) (*PaymentResult, error)
	CreateCheckout(ctx context.Context, req CreateCheckoutReq) (*CheckoutResult, error)
	GetCheckout(ctx context.Context, checkoutID string) (*PaymentResult, error)
	RefundPayment(ctx context.Context, req RefundPaymentReq) (*RefundResult, error)
	CreateCardOnFile(ctx context.Context, userID, cardToken string) (*CardOnFile, error)
	CreateCardOnFileRaw(ctx context.Context, userID, cardNumber string, expMonth, expYear int, cvc string) (*CardOnFile, error)
	GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error)
	DeleteCardOnFile(ctx context.Context, cardID string) error
}
