export type LeaseDetailStatus = '未收款' | '部分收款' | '已收款';
export type BillArchiveStatus = '已归档' | '未归档' | '草稿';
export type AssetOwnership = '自有' | '租赁' | '挂靠';
export type ListViewMode = 'all' | 'unpaid';
export type MaintenanceBearBy = '客户承担' | '我司承担';
export type ContractEndMode = 'term' | 'date';

export type { ExemptionPolicy } from './utils/constants';

export interface LedgerLineItem {
  reason: string;
  amount: number;
  remark: string;
}

export interface OperationHistoryEntry {
  operatedAt: string;
  operatorName: string;
  field: string;
  before: string;
  after: string;
}

export interface LeaseLedgerRow {
  id: string;
  status: LeaseDetailStatus;
  archiveStatus: BillArchiveStatus;
  maintainerName: string;
  maintainerTime?: string;
  year: number;
  month: number;
  dept: string;
  salesman: string;
  paymentDueDate?: string;
  paymentDate?: string;
  plateNo: string;
  vehicleBrand: string;
  vehicleModel: string;
  vehicleType?: string;
  customerName: string;
  projectName: string;
  valueAddedService: string;
  exemptionPolicy: string;
  pickupDate: string;
  contractStartDate: string;
  contractEndDate: string;
  contractEndMode?: ContractEndMode;
  leaseTermMonths?: number;
  periodStartDate: string;
  returnDate: string;
  avgDays: number;
  actualLeaseDays?: number;
  deposit: string | number;
  contractRent: number;
  paymentCycleMonths: number;
  serviceFee: number;
  maintenancePackageEnabled: boolean;
  maintenanceUnitPricePerKm: number;
  mileage: number;
  mileageDeductionRate?: number;
  customerBearsMaintenance: boolean;
  linkedMaintenanceIds: string[];
  linkedAccidentIds: string[];
  linkedReceiptIds: string[];
  hydrogenBorneBy: '我司承担' | '客户承担' | '';
  isLatestBill: boolean;
  insurancePurchaseAmount?: number;
  insuranceEffectiveDays?: number;
  otherIncomeItems?: LedgerLineItem[];
  otherDeductionItems?: LedgerLineItem[];
  operationHistory?: OperationHistoryEntry[];
  receivableTotal: number;
  receivableRent: number;
  monthlyIncome: number;
  monthlyRent: number;
  maintenanceIncome: number;
  insuranceSurcharge: number;
  opsFeeIncome: number;
  otherIncome: number;
  mileageDeduction: number;
  otherDeduction: number;
  receivedAmount: number;
  invoiceDate: string;
  actualPaymentDate: string;
  paymentMethod: string;
  vehicleStandardCost: number;
  vehicleActualCost: number;
  insuranceFee: number;
  hydrogenFee: number;
  opsFeeCost: number;
  brokerageFee: number;
  otherCost: number;
  totalCost: number;
  profitLoss: number;
  gpsMileage: string;
  otherDeductionDetail: string;
  assetOwnership: AssetOwnership;
  assetOwner?: string;
  signingCompany: string;
  remark: string;
}

export interface LeaseLedgerFilters {
  year: string;
  month: string;
  dept: string;
  salesman: string;
  plateNos: string[];
  customerName: string;
  status: string;
  paymentFrom: string;
  paymentTo: string;
}

export const EMPTY_LEASE_FILTERS: LeaseLedgerFilters = {
  year: '',
  month: '',
  dept: '',
  salesman: '',
  plateNos: [],
  customerName: '',
  status: '',
  paymentFrom: '',
  paymentTo: '',
};

export interface LeaseKpiSummary {
  count: number;
  receivableTotal: number;
  receivedAmount: number;
  unreceived: number;
  totalCost: number;
  profitLoss: number;
}

export interface ReceiptRecord {
  id: string;
  arrivalTime: string;
  customerName: string;
  amount: number;
  remark: string;
  invoiceDate?: string;
}

export interface BiMileageRecord {
  plateNo: string;
  year: number;
  month: number;
  mileageKm: number;
}

export interface HydrogenFeeRecord {
  plateNo: string;
  year: number;
  month: number;
  amount: number;
  status: string;
  refuelDate: string;
  stationName: string;
  volume: number;
  unitCost: number;
  totalCost: number;
  borneBy: '我司承担' | '客户承担';
}

export interface MaintenanceOrder {
  id: string;
  plateNo: string;
  orderNo: string;
  type: string;
  bearBy: MaintenanceBearBy;
  amount: number;
  completedAt: string;
}

/** 还车应结款费用明细（原型种子） */
export interface ReturnSettlementFeeRecord {
  id: string;
  plateNo: string;
  feeItem: string;
  amount: number;
  settlementDate: string;
}

/** 维修保养明细台账（原型种子） */
export interface MaintenanceLedgerRecord {
  id: string;
  plateNo: string;
  orderNo: string;
  type: string;
  repairDate: string;
  totalCost: number;
}

export interface AccidentRecord {
  id: string;
  plateNo: string;
  accidentNo: string;
  insuranceSurcharge: number;
  occurredAt: string;
  remark: string;
}
