/**
 * @ai-summary Type definitions for ownership-costs feature
 * @ai-context Tracks vehicle ownership costs (insurance, registration, tax, other)
 */

// Cost types supported by ownership-costs feature
export type OwnershipCostType = 'insurance' | 'registration' | 'tax' | 'other';

// Cost interval types (one_time added for things like purchase price)
export type CostInterval = 'monthly' | 'semi_annual' | 'annual' | 'one_time';

// Payments per year for each interval type
export const PAYMENTS_PER_YEAR: Record<CostInterval, number> = {
  monthly: 12,
  semi_annual: 2,
  annual: 1,
  one_time: 0, // Special case: calculated differently
} as const;

export interface OwnershipCost {
  id: string;
  userId: string;
  vehicleId: string;
  documentId?: string;
  costType: OwnershipCostType;
  description?: string;
  amount: number;
  interval: CostInterval;
  startDate: Date;
  endDate?: Date;
  createdAt: Date;
  updatedAt: Date;
}

export interface CreateOwnershipCostRequest {
  vehicleId: string;
  documentId?: string;
  costType: OwnershipCostType;
  description?: string;
  amount: number;
  interval: CostInterval;
  startDate: string; // ISO date string
  endDate?: string;  // ISO date string
}

export interface UpdateOwnershipCostRequest {
  documentId?: string | null;
  costType?: OwnershipCostType;
  description?: string | null;
  amount?: number;
  interval?: CostInterval;
  startDate?: string;
  endDate?: string | null;
}

export interface OwnershipCostResponse {
  id: string;
  userId: string;
  vehicleId: string;
  documentId?: string;
  costType: OwnershipCostType;
  description?: string;
  amount: number;
  interval: CostInterval;
  startDate: string;
  endDate?: string;
  createdAt: string;
  updatedAt: string;
}

// Aggregated cost statistics for TCO calculation
export interface OwnershipCostStats {
  insuranceCosts: number;
  registrationCosts: number;
  taxCosts: number;
  otherCosts: number;
  totalCosts: number;
}

// Fastify-specific types for HTTP handling
export interface CreateOwnershipCostBody {
  vehicleId: string;
  documentId?: string;
  costType: OwnershipCostType;
  description?: string;
  amount: number;
  interval: CostInterval;
  startDate: string;
  endDate?: string;
}

export interface UpdateOwnershipCostBody {
  documentId?: string | null;
  costType?: OwnershipCostType;
  description?: string | null;
  amount?: number;
  interval?: CostInterval;
  startDate?: string;
  endDate?: string | null;
}

export interface OwnershipCostParams {
  id: string;
}

export interface VehicleParams {
  vehicleId: string;
}
