package models

import (
	"encoding/json"
	"time"

	"github.com/google/uuid"
)

type Invoice struct {
	ID            uuid.UUID       `db:"id" json:"id"`
	TenantID      uuid.UUID       `db:"tenant_id" json:"tenant_id"`
	CaseID        uuid.UUID       `db:"case_id" json:"case_id"`
	InvoiceNumber string          `db:"invoice_number" json:"invoice_number"`
	ClientName    string          `db:"client_name" json:"client_name"`
	ClientAddress *string         `db:"client_address" json:"client_address,omitempty"`
	Items         json.RawMessage `db:"items" json:"items"`
	Subtotal      float64         `db:"subtotal" json:"subtotal"`
	TaxRate       float64         `db:"tax_rate" json:"tax_rate"`
	TaxAmount     float64         `db:"tax_amount" json:"tax_amount"`
	Total         float64         `db:"total" json:"total"`
	Status        string          `db:"status" json:"status"`
	IssuedAt      *string         `db:"issued_at" json:"issued_at,omitempty"`
	DueAt         *string         `db:"due_at" json:"due_at,omitempty"`
	PaidAt        *time.Time      `db:"paid_at" json:"paid_at,omitempty"`
	Notes         *string         `db:"notes" json:"notes,omitempty"`
	CreatedBy     uuid.UUID       `db:"created_by" json:"created_by"`
	CreatedAt     time.Time       `db:"created_at" json:"created_at"`
	UpdatedAt     time.Time       `db:"updated_at" json:"updated_at"`
}

type InvoiceItem struct {
	Description     string  `json:"description"`
	DurationMinutes int     `json:"duration_minutes,omitempty"`
	HourlyRate      float64 `json:"hourly_rate,omitempty"`
	Amount          float64 `json:"amount"`
	TimeEntryID     *string `json:"time_entry_id,omitempty"`
}
