// Zoho Books API Response Types

export interface ZohoBooksContact {
  contact_id: string;
  contact_name: string;
  customer_name: string;
  vendor_name: string;
  company_name: string;
  website: string;
  language_code: string;
  language_code_formatted: string;
  contact_type: 'customer' | 'vendor';
  contact_type_formatted: string;
  status: 'active' | 'inactive';
  customer_sub_type: 'business' | 'individual';
  source: string;
  is_linked_with_zohocrm: boolean;
  payment_terms: number;
  payment_terms_label: string;
  currency_id: string;
  twitter: string;
  facebook: string;
  currency_code: string;
  outstanding_receivable_amount: number;
  outstanding_receivable_amount_bcy: number;
  outstanding_payable_amount: number;
  outstanding_payable_amount_bcy: number;
  unused_credits_receivable_amount: number;
  unused_credits_receivable_amount_bcy: number;
  unused_credits_payable_amount: number;
  unused_credits_payable_amount_bcy: number;
  first_name: string;
  last_name: string;
  email: string;
  phone: string;
  mobile: string;
  has_photo: boolean;
  portal_status: 'enabled' | 'disabled';
  portal_status_formatted: string;
  created_time: string;
  created_time_formatted: string;
  last_modified_time: string;
  last_modified_time_formatted: string;
  custom_fields: any[];
  custom_field_hash: Record<string, any>;
  tags: string[];
  ach_supported: boolean;
  has_attachment: boolean;
  pan_no: string;
}

export interface ZohoBooksInvoice {
  ach_payment_initiated: boolean;
  invoice_id: string;
  zcrm_potential_id: string;
  customer_id: string;
  zcrm_potential_name: string;
  customer_name: string;
  company_name: string;
  status: 'draft' | 'sent' | 'invoiced' | 'paid' | 'overdue' | 'void';
  invoice_number: string;
  reference_number: string;
  date: string;
  due_date: string;
  due_days: string;
  email: string;
  type: 'invoice' | 'estimate' | 'creditnote';
  project_name: string;
  billing_address: {
    address: string;
    street2: string;
    city: string;
    state: string;
    zipcode: string;
    country: string;
    phone: string;
    fax: string;
    attention: string;
  };
  shipping_address: {
    address: string;
    street2: string;
    city: string;
    state: string;
    zipcode: string;
    country: string;
    phone: string;
    fax: string;
    attention: string;
  };
  country: string;
  phone: string;
  created_by: string;
  total: number;
  balance: number;
  payment_expected_date: string;
  custom_fields: any[];
  custom_field_hash: Record<string, any>;
  tags: string[];
  salesperson_name: string;
  shipping_charge: number;
  adjustment: number;
  created_time: string;
  last_modified_time: string;
  updated_time: string;
  is_viewed_by_client: boolean;
  has_attachment: boolean;
  client_viewed_time: string;
  is_emailed: boolean;
  color_code: string;
  current_sub_status_id: string;
  current_sub_status: string;
  currency_id: string;
  schedule_time: string;
  currency_code: string;
  currency_symbol: string;
  is_pre_gst: boolean;
  template_type: string;
  no_of_copies: number;
  show_no_of_copies: boolean;
  transaction_type: string;
  reminders_sent: number;
  last_reminder_sent_date: string;
  last_payment_date: string;
  template_id: string;
  documents: string;
  salesperson_id: string;
  write_off_amount: number;
  exchange_rate: number;
  unprocessed_payment_amount: number;
}

export interface ZohoBooksExpense {
  expense_id: string;
  date: string;
  user_name: string;
  paid_through_account_name: string;
  account_name: string;
  description: string;
  currency_id: string;
  currency_code: string;
  bcy_total: number;
  bcy_total_without_tax: number;
  total: number;
  total_without_tax: number;
  is_billable: boolean;
  reference_number: string;
  customer_id: string;
  is_personal: boolean;
  customer_name: string;
  vendor_id: string;
  vendor_name: string;
  status: 'billable' | 'nonbillable';
  created_time: string;
  last_modified_time: string;
  expense_receipt_name: string;
  exchange_rate: number;
  distance: number;
  mileage_rate: number;
  mileage_unit: string;
  mileage_type: string;
  expense_type: string;
  report_id: string;
  start_reading: string;
  end_reading: string;
  report_name: string;
  report_number: string;
  has_attachment: boolean;
  custom_fields_list: string;
}

export interface ZohoBooksSalesOrder {
  salesorder_id: string;
  zcrm_potential_id: string;
  zcrm_potential_name: string;
  customer_name: string;
  customer_id: string;
  email: string;
  delivery_date: string;
  company_name: string;
  color_code: string;
  current_sub_status_id: string;
  current_sub_status: string;
  pickup_location_id: string;
  salesorder_number: string;
  reference_number: string;
  date: string;
  shipment_date: string;
  shipment_days: string;
  due_by_days: string;
  due_in_days: string;
  currency_id: string;
  source: string;
  currency_code: string;
  total: number;
  bcy_total: number;
  total_invoiced_amount: number;
  created_time: string;
  last_modified_time: string;
  is_emailed: boolean;
  quantity_invoiced: number;
  order_status: 'draft' | 'confirmed' | 'delivered' | 'cancelled';
  invoiced_status: string;
  paid_status: string;
  shipped_status: string;
  status: 'draft' | 'confirmed' | 'delivered' | 'cancelled';
  order_fulfillment_type: string;
  is_manually_fulfilled: boolean;
  salesperson_name: string;
  has_attachment: boolean;
  tags: string[];
  custom_fields_list: string;
  delivery_method: string;
  delivery_method_id: string;
  is_viewed_in_mail: boolean;
  mail_first_viewed_time: string;
  mail_last_viewed_time: string;
  is_scheduled_for_quick_shipment_create: boolean;
}

export interface ZohoBooksPurchaseOrder {
  purchaseorder_id: string;
  vendor_id: string;
  vendor_name: string;
  company_name: string;
  order_status: 'draft' | 'confirmed' | 'received' | 'cancelled';
  billed_status: string;
  received_status: string;
  status: 'draft' | 'confirmed' | 'received' | 'cancelled';
  color_code: string;
  current_sub_status_id: string;
  current_sub_status: string;
  purchaseorder_number: string;
  reference_number: string;
  date: string;
  delivery_date: string;
  expected_delivery_date: string;
  delivery_days: string;
  due_by_days: string;
  due_in_days: string;
  currency_id: string;
  currency_code: string;
  price_precision: string;
  total: number;
  has_attachment: boolean;
  tags: string[];
  created_time: string;
  last_modified_time: string;
  quantity_yet_to_receive: number;
  quantity_marked_as_received: number;
  is_po_marked_as_received: boolean;
  receives: any[];
  client_viewed_time: string;
  is_viewed_by_client: boolean;
}

export interface ZohoBooksBill {
  bill_id: string;
  vendor_id: string;
  vendor_name: string;
  status: 'draft' | 'open' | 'paid' | 'overdue' | 'void';
  color_code: string;
  current_sub_status_id: string;
  current_sub_status: string;
  bill_number: string;
  reference_number: string;
  date: string;
  due_date: string;
  due_days: string;
  currency_id: string;
  currency_code: string;
  price_precision: number;
  exchange_rate: number;
  total: number;
  tds_total: number;
  balance: number;
  unprocessed_payment_amount: number;
  created_time: string;
  last_modified_time: string;
  is_opening_balance: string;
  attachment_name: string;
  has_attachment: boolean;
  tags: string[];
  is_uber_bill: boolean;
  is_tally_bill: boolean;
  entity_type: string;
  client_viewed_time: string;
  is_viewed_by_client: boolean;
  is_bill_reconciliation_violated: boolean;
  balance_due: number;
}

export interface ZohoBooksApiResponse<T> {
  status: 'success' | 'error';
  message: string;
  data: {
    data: T[];
    info: {
      count: number;
      moreRecords: boolean;
      page: number;
    };
  };
  timestamp: string;
}

// Dashboard specific types
export interface ZohoBooksKPIData {
  totalCustomers: number;
  totalVendors: number;
  totalInvoices: number;
  totalExpenses: number;
  totalSalesOrders: number;
  totalPurchaseOrders: number;
  totalBills: number;
  outstandingReceivables: number;
  outstandingPayables: number;
  totalRevenue: number;
  totalExpensesAmount: number;
}

export interface ZohoBooksDashboardState {
  contacts: ZohoBooksContact[];
  invoices: ZohoBooksInvoice[];
  expenses: ZohoBooksExpense[];
  salesOrders: ZohoBooksSalesOrder[];
  purchaseOrders: ZohoBooksPurchaseOrder[];
  bills: ZohoBooksBill[];
  kpiData: ZohoBooksKPIData;
  loading: boolean;
  error: string | null;
  lastUpdated: string | null;
}
