package forms

import (
	"time"

	"github.com/shopspring/decimal"
	"github.com/stripe/stripe-go/v76"
)

// SetupIntent setupIntent API response
type SetupIntent struct {
	PublicKey    string `json:"public_key"`
	ClientSecret string `json:"client_secret"`
}

// PaymentMethod is the response of payment method API
type StripePaymentMethod struct {
	ID             string          `json:"id"`
	Card           *Card           `json:"card"`
	BillingDetails *BillingDetails `json:"billing_details"`
}

// Card is the credit card
type Card struct {
	Brand       string `json:"brand"`
	Country     string `json:"country"`
	ExpMonth    int64  `json:"exp_month,string"`
	ExpYear     int64  `json:"exp_year,string"`
	Fingerprint string `json:"fingerprint"`
	Funding     string `json:"funding"`
	Last4       string `json:"last4"`
}

// BillingDetails is the user detail billing information
type BillingDetails struct {
	Address *Address `json:"address"`
	Email   *string  `json:"email"`
	Name    string   `json:"name"`
	Phone   *string  `json:"phone"`
}

// Address is the billing Address
type Address struct {
	City       string `json:"city"`
	Country    string `json:"country"`
	Line1      string `json:"line1"`
	Line2      string `json:"line2"`
	PostalCode string `json:"postal_code"`
	State      string `json:"state"`
}

type StripeCustomerInfo struct {
	ID            string   `json:"id"`
	TenantID      string   `json:"dbaas_id"`
	Email         string   `json:"email"`
	Name          string   `json:"name"`
	Description   string   `json:"description"`
	DefaultSource string   `json:"default_source"`
	Address       *Address `json:"address"`
}

// Invoice is the response of invoice API
type StripeInvoice struct {
	AmountDue  decimal.Decimal `json:"amount_due"`
	AmountPaid decimal.Decimal `json:"amount_paid"`
	Created    int64           `json:"created,string"`
	Currency   string          `json:"currency"`
	DueDate    int64           `json:"due_date,string"`
	CreditUsed decimal.Decimal `json:"credit_used"`
	ID         string          `json:"id"`
	Number     string          `json:"number"`
	InvoicePDF string          `json:"invoice_pdf"`
	Total      decimal.Decimal `json:"total"`
	Paid       bool            `json:"paid"`
	Status     string          `json:"status"`
	Tax        decimal.Decimal `json:"-"`
	TaxRate    decimal.Decimal `json:"-"`
	SubTotal   decimal.Decimal `json:"-"`
	CustomerID string          `json:"-"`
	StartDate  time.Time       `json:"-"`
	EndDate    time.Time       `json:"-"`
	// Metadata carries the invoice metadata written at push time
	// (invoice_start / invoice_end / merged_from_invoice_ids /
	// merged_months / charge_mode). Internal only — kept out of the
	// public API surface via json:"-".
	Metadata          map[string]string                `json:"-"`
	StatusTransitions *stripe.InvoiceStatusTransitions `json:"-"`
}

type StripeInvoiceDetail struct {
	StripeInvoice
	PubicKey            string `json:"public_key"`
	ClientSecret        string `json:"client_secret"`
	PaymentIntentID     string `json:"payment_intent_id"`
	PaymentIntentStatus string `json:"payment_intent_status"`
}

type StripeCalculateTaxResult struct {
	Amount decimal.Decimal `json:"amount"`
	// The ID of an existing [Customer](https://stripe.com/docs/api/customers/object) used for the resource.
	Inclusive        bool   `json:"inclusive"`
	TaxAbilityReason string `json:"tax_ability_reason"`
	// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
	Country string `json:"country"`
	// The tax rate percentage as a string. For example, 8.5% is represented as `"8.5"`.
	PercentageDecimal string `json:"percentage_decimal"`
	// State, county, province, or region.
	State string `json:"state"`
	// The tax type, such as `vat` or `sales_tax`.
	TaxType string `json:"tax_type"`
}

type CardValidateResult struct {
	Status string `json:"status"`

	PaymentIntentID string `json:"payment_intent_id"`

	ClientSecret string `json:"client_secret"`

	PublicKey string `json:"public_key"`
}
