import { Contact } from "@/redux/api/contactApi";
import { SuggestedProject, SuggestedProperty } from "@/redux/api/leadApi";

export type Location = {
  id: string;
  name: string;
};

export type Lead = {
  id: string;
  leadScore: number;
  priority: string;
  interestType: string;
  name: string;
  email: string;
  notes?: string;
  reason?: string;
  leadStage: { color?: string; id?: string };
  project: { projectName?: string; id?: string };
  phoneNumber: string;
  lastContacted: string | Date;
  // assignedTo: string;
  contact?: Contact;
  createdOn: string | Date;
  createdAt: string | Date;
  updatedAt: string | Date;
  leadStageName: string;
  company?: { id?: string; name?: string };
  source?: { id?: string; name?: string };
  updatedOn?: string | Date;
  contact?: {
    id: string;
    firstName: string;
    lastName: string;
    name: string;
    email: string;
    leadStage: {color?: string, id?: string};
    project: {projectName?: string, id?: string};
    phoneNumber: string;
    lastContacted: string | Date;
    // assignedTo: string;
    contact?: Contact
    createdOn: string | Date;
    updatedOn: string | Date;
    createdAt: string | Date;
    updatedAt: string | Date;
    leadStageName: string;
    company?: {id?: string, name?: string};
    source?: {id?: string, name?: string};
    contact?: {
        id: string;
        firstName: string;
        lastName: string;
        name: string;
        companyName: string;
        primaryPhone?: {
            number: string;
        };
        phone?: {
            number: string;
        }[];
        email?: string;
    };
    phone?: {
      number: string;
    }[];
    email?: string;
  };
  assignedTo?: {
    id: string;
    firstName: string;
    lastName: string;
  };
  unit?: {
    unitNumber?: string;
    id?: string;
  };
  propertyType?: [
    {
      name?: string;
      id?: string;
    }
  ];
  configuration?: [
    {
      name?: string;
      id?: string;
    }
  ];
  budget?: number;
  leaseAmount?: number;
  monthlyRent?: number;
  preferredLocalities?: Location;
  preferredCity?: Location;
  preferredState?: Location;
  shortlisted?: SuggestedProperty[];
  removed?: SuggestedProperty[];
  shortlistedProject?: SuggestedProject[];
  removedProject?: SuggestedProject[];
  customFields?: Record<string, any>;
};

export interface LeadActivity {
  id: string;
  name: string;
  description: string;
  points: number;
  defaultPoints: number;
}

export interface MonthlyLeadData {
  count: number;
  year: number;
  month: string;
  monthNum: number;
  changeDirection: string;
  change: number;
}

export interface LeadScoreBucket {
  _id: string; // 'Unknown' or bucket name
  count: number;
}

export interface LeadStage {
  count: number;
  leadStageId: string;
  stageName: string;
}

export interface StageCounts {
  stages: LeadStage[];
  totalCount: number;
}

export interface ConversionRateEntry {
  total: number;
  won: number;
  year: number;
  month: string;
  monthNum: number;
  conversionRate: number;
  changeDirection: string;
  change: number;
}

export interface LeadAnalyticsResponse {
  data: {
    totalPerMonth: MonthlyLeadData[];
    leadScores: LeadScoreBucket[];
    stageCounts: StageCounts[];
    conversionRate: ConversionRateEntry[];
  };
}

export interface BulkLeadUploadResultData {
  created: number;
  skipped: number;
  totalRequested: number;
  errors: string[];
}

export interface LeadImportAggregateResult {
  totalCreated: number;
  totalSkipped: number;
  totalRequested: number;
  allErrors: string[];
}
