package model

import (
	"database/sql"
	"time"

	"gorm.io/gorm"
)

type ARTable struct {
	ID                                      int            `json:"id" gorm:"primaryKey"`
	BillMonth                               *string        `json:"bill_month,omitempty" csv:"bill_month"`
	StartDate                               *time.Time     `json:"start_date,omitempty" csv:"start_date"`
	EndDate                                 *time.Time     `json:"end_date,omitempty" csv:"end_date"`
	TenantID                                *string        `json:"tenant_id,omitempty" csv:"tenant_id"`
	StripeAmount                            *string        `json:"stripe_amount,omitempty" csv:"stripe_amount"`
	StripeTaxRate                           *string        `json:"stripe_tax_rate,omitempty" csv:"stripe_tax_rate"`
	StripeAmountIncludingTax                *string        `json:"stripe_amount_including_tax,omitempty" csv:"stripe_amount_including_tax"`
	StripeInvoiceNumber                     *string        `json:"stripe_invoice_number,omitempty" csv:"stripe_invoice_number"`
	WireTransferAmount                      *float64       `json:"wire_transfer_amount,omitempty" csv:"wire_transfer_amount"`
	MarketplaceAmount                       *float64       `json:"marketplace_amount,omitempty" csv:"marketplace_amount"`
	PrepaymentCredits                       *float64       `json:"prepayment_credits,omitempty" csv:"prepayment_credits"`
	TotalAmount                             *float64       `json:"total_amount,omitempty" csv:"total_amount"`
	InvoiceAmount                           *float64       `json:"invoice_amount,omitempty" csv:"invoice_amount"`
	NumberOfSegments                        *int           `json:"number_of_segments,omitempty" csv:"number_of_segments"`
	SegmentAStartDate                       *time.Time     `json:"segment_a_start_date,omitempty" csv:"segment_a_start_date"`
	SegmentAEndDate                         *time.Time     `json:"segment_a_end_date,omitempty" csv:"segment_a_end_date"`
	SegmentAAmount                          *float64       `json:"segment_a_amount,omitempty" csv:"segment_a_amount"`
	SegmentBStartDate                       *time.Time     `json:"segment_b_start_date,omitempty" csv:"segment_b_start_date"`
	SegmentBEndDate                         *time.Time     `json:"segment_b_end_date,omitempty" csv:"segment_b_end_date"`
	SegmentBAmount                          *float64       `json:"segment_b_amount,omitempty" csv:"segment_b_amount"`
	SegmentCStartDate                       *time.Time     `json:"segment_c_start_date,omitempty" csv:"segment_c_start_date"`
	SegmentCEndDate                         *time.Time     `json:"segment_c_end_date,omitempty" csv:"segment_c_end_date"`
	SegmentCAmount                          *float64       `json:"segment_c_amount,omitempty" csv:"segment_c_amount"`
	StripeInvoice                           *string        `json:"stripe_invoice,omitempty" csv:"stripe_invoice" gorm:"-"`
	StripeInvoicePaid                       *string        `json:"stripe_invoice_paid,omitempty" csv:"stripe_invoice_paid"`
	StripeInvoiceFinalizedDate              *string        `json:"stripe_invoice_finalized_date,omitempty" csv:"stripe_invoice_finalized_date"`
	StripeInvoicePaidDate                   *string        `json:"stripe_invoice_paid_date,omitempty" csv:"stripe_invoice_paid_date"`
	RawStarterAmount                        *float64       `json:"raw_starter_amount,omitempty" csv:"raw_starter_amount"`
	RawDedicatedAmount                      *float64       `json:"raw_dedicated_amount,omitempty" csv:"raw_dedicated_amount"`
	RawSupportAmount                        *float64       `json:"raw_support_amount,omitempty" csv:"raw_support_amount"`
	RawByocAmount                           *float64       `json:"raw_byoc_amount,omitempty" csv:"raw_byoc_amount"`
	ChannelLossAmount                       *float64       `json:"channel_loss_amount,omitempty" csv:"channel_loss_amount"`
	StarterAllocatedLoss                    *float64       `json:"starter_allocated_loss,omitempty" csv:"starter_allocated_loss"`
	DedicatedAllocatedLoss                  *float64       `json:"dedicated_allocated_loss,omitempty" csv:"dedicated_allocated_loss"`
	SupportAllocatedLoss                    *float64       `json:"support_allocated_loss,omitempty" csv:"support_allocated_loss"`
	RawProgramCreditAmountStarter           *float64       `json:"raw_program_credit_amount_starter,omitempty"`
	RawRedeemCreditAmountSupport            *float64       `json:"raw_redeem_credit_amount_support,omitempty"`
	RawRedeemCreditAmountDedicated          *float64       `json:"raw_redeem_credit_amount_dedicated,omitempty"`
	RawProgramCreditAmountDedicated         *float64       `json:"raw_program_credit_amount_dedicated,omitempty"`
	RawRedeemCreditAmountStarter            *float64       `json:"raw_redeem_credit_amount_starter,omitempty"`
	RawCustomerSuccessCreditAmountStarter   *float64       `json:"raw_customer_success_credit_amount_starter,omitempty"`
	RawCustomerSuccessCreditAmountSupport   *float64       `json:"raw_customer_success_credit_amount_support,omitempty"`
	RawProgramCreditAmountSupport           *float64       `json:"raw_program_credit_amount_support,omitempty"`
	RawCustomerSuccessCreditAmountDedicated *float64       `json:"raw_customer_success_credit_amount_dedicated,omitempty"`
	RawProgramCreditAmountByoc              *float64       `json:"raw_program_credit_amount_byoc,omitempty"`
	RawRedeemCreditAmountByoc               *float64       `json:"raw_redeem_credit_amount_byoc,omitempty"`
	RawCustomerSuccessCreditAmountByoc      *float64       `json:"raw_customer_success_credit_amount_byoc,omitempty"`
	CreatedAt                               time.Time      `json:"created_at,omitempty"`
	UpdatedAt                               sql.NullTime   `json:"updated_at,omitempty"`
	DeletedAt                               gorm.DeletedAt `json:"deleted_at,omitempty"`
	Valid                                   bool           `json:"valid,omitempty"`
}

func (ARTable) TableName() string {
	return "ar_table"
}

type ARStripeInvoice struct {
	ID            int            `json:"id" gorm:"primaryKey"`
	BillMonth     string         `json:"bill_month,omitempty" csv:"bill_month"`
	StripeInvoice string         `json:"stripe_invoice,omitempty" csv:"stripe_invoice"`
	TenantID      string         `json:"tenant_id,omitempty" csv:"tenant_id"`
	CreatedAt     time.Time      `json:"created_at,omitempty"`
	UpdatedAt     sql.NullTime   `json:"updated_at,omitempty"`
	DeletedAt     gorm.DeletedAt `json:"deleted_at,omitempty"`
}

func (ARStripeInvoice) TableName() string {
	return "ar_stripe_invoice"
}

type UploadBody struct {
	Type  string `json:"type"`
	ID    string `json:"id"`
	Files []File `json:"files"`
}

type File struct {
	Name       string `json:"name"`
	Base64Data string `json:"base64Data"`
}
