export interface CrmDashboardFilters {
  dateFrom?: string | null;
  dateTo?: string | null;
  branch?: string | null;
  salesman?: string | null;
  projectPartyRole?: string | null;
  productType?: string | null;
}

export interface CrmDashboardOption {
  id: string;
  code: string;
  label: string;
}

export interface CrmDashboardSalesOption {
  id: string;
  name: string;
}

export interface CrmDashboardReferenceData {
  branches: CrmDashboardOption[];
  salesmen: CrmDashboardSalesOption[];
  productTypes: CrmDashboardOption[];
  projectPartyRoles: CrmDashboardOption[];
}

export interface CrmDashboardSummary {
  lead: {
    leadCount: number;
    newLeads: number;
    unassignedLeads: number;
    averageLeadAgingDays: number;
  };
  enquiry: {
    enquiryCount: number;
    activeEnquiries: number;
    wonCount: number;
    lostCount: number;
    hotEnquiries: number;
    enquiryValue: number;
  };
  quotation: {
    draftQuotations: number;
    pendingApproval: number;
    approvedQuotations: number;
    sentQuotations: number;
  };
  revenue: {
    quotationValue: number;
    wonValue: number;
    lostValue: number;
  };
}

export interface CrmDashboardFunnelStep {
  key: string;
  label: string;
  count: number;
  value: number;
  conversionRate: number | null;
}

export interface CrmDashboardRevenueRow {
  customerId: string;
  customerCode: string;
  customerName: string;
  roleCode: string;
  revenue: number;
  quotationCount: number;
  wonRevenue: number;
}

export interface CrmDashboardSalesRankingRow {
  salesPersonId: string;
  salesPersonName: string;
  leadCount: number;
  enquiryCount: number;
  quotationCount: number;
  approvedQuotations: number;
  wonRevenue: number;
  conversionRate: number;
}

export interface CrmDashboardFollowupSummary {
  dueToday: number;
  dueThisWeek: number;
  overdue: number;
  completed: number;
}

export interface CrmDashboardFollowupRow {
  id: string;
  sourceType: 'enquiry' | 'quotation';
  followupDate: string;
  customerName: string;
  enquiryName: string;
  assignedSalesName: string | null;
  outcome: string | null;
}

export interface CrmDashboardApprovalSummary {
  pendingApprovals: number;
  approvedToday: number;
  rejectedToday: number;
  returnedToday: number;
  averageApprovalTimeHours: number;
}

export interface CrmDashboardApprovalRow {
  id: string;
  entityCode: string | null;
  entityTitle: string | null;
  workflowName: string;
  currentStepRoleName: string | null;
  requestedAt: string;
}

export interface CrmDashboardHotProjectRow {
  enquiryId: string;
  enquiryCode: string;
  projectName: string;
  customerName: string;
  value: number;
  assignedSalesName: string | null;
  probability: number | null;
}

export interface CrmDashboardResponse {
  success: boolean;
  time: string;
  message: string;
  filters: Required<CrmDashboardFilters>;
  referenceData: CrmDashboardReferenceData;
  summary: CrmDashboardSummary;
  funnel: CrmDashboardFunnelStep[];
  revenueAnalytics: {
    topEndCustomers: CrmDashboardRevenueRow[];
    topBillingCustomers: CrmDashboardRevenueRow[];
    topContractors: CrmDashboardRevenueRow[];
    topConsultants: CrmDashboardRevenueRow[];
  };
  salesRanking: CrmDashboardSalesRankingRow[];
  followups: {
    summary: CrmDashboardFollowupSummary;
    upcoming: CrmDashboardFollowupRow[];
  };
  approvals: {
    summary: CrmDashboardApprovalSummary;
    myPendingApprovals: CrmDashboardApprovalRow[];
  };
  hotProjects: CrmDashboardHotProjectRow[];
  visibility: {
    canViewCommercialData: boolean;
    canViewApprovalData: boolean;
  };
}
