/**
 * Billing Type Definitions
 * Defines the structure of billing-related objects
 */

export interface UsageReport {
  tenantId: string
  timeRange: {
    start: Date
    end: Date
  }
  granularity: 'SECOND' | 'MINUTE' | 'HOUR' | 'DAY'
  totalCost: number
  currency: string
  byResource: ResourceUsage[]
  byMetric: MetricUsage[]
  breakdown: CostBreakdown
}

export interface ResourceUsage {
  resourceId: string
  resourceName: string
  resourceType: string
  cost: number
  quantity: number
  unit: string
}

export interface MetricUsage {
  metricType: string
  cost: number
  quantity: number
  unit: string
}

export interface CostBreakdown {
  total: number
  byResource: Array<{
    resourceId: string
    resourceName: string
    cost: number
    percentage: number
  }>
  byService: Array<{
    service: string
    cost: number
    percentage: number
  }>
  byRegion: Array<{
    region: string
    cost: number
    percentage: number
  }>
  allocations: Array<{
    key: string
    value: string
    cost: number
    percentage: number
  }>
}

export interface Invoice {
  id: string
  tenantId: string
  invoiceNumber: string
  billingPeriodStart: Date
  billingPeriodEnd: Date
  subtotal: number
  tax: number
  total: number
  currency: string
  status: 'DRAFT' | 'PENDING' | 'PAID' | 'OVERDUE' | 'CANCELLED'
  dueDate: Date | null
  paidAt: Date | null
  lineItems: InvoiceLineItem[]
  createdAt: Date
  updatedAt: Date
}

export interface InvoiceLineItem {
  id: string
  description: string
  quantity: number
  unitPrice: number
  total: number
  resourceId: string | null
}

export interface InvoiceListResult {
  invoices: Invoice[]
  total: number
}

export interface Budget {
  id: string
  tenantId: string
  name: string
  amount: number
  currency: string
  period: 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'QUARTERLY' | 'YEARLY'
  startDate: Date
  endDate: Date | null
  alertThresholds: number[]
  filters: Record<string, unknown>
  currentSpend: number
  remaining: number
  createdAt: Date
  updatedAt: Date
}

export interface BillingAlert {
  id: string
  tenantId: string
  name: string
  alertType: 'BUDGET' | 'THRESHOLD' | 'ANOMALY' | 'FORECAST'
  threshold: number | null
  condition: Record<string, unknown>
  enabled: boolean
  lastTriggeredAt: Date | null
  createdAt: Date
  updatedAt: Date
}

