import { Document, Types } from 'mongoose';
import { IPaginateModel } from '@/shared/interfaces/model.interface';
import { AuditFields } from '@/shared/types/common';
import {
  LeadInterestType,
  LeadBuyingPreference,
} from '@/shared/constants/enum.constant';

export interface ICaptureLeadBase {
  name: string;
  platform: string;
  interestType: LeadInterestType;
  company: Types.ObjectId;
  source: Types.ObjectId;
  integrationStatus?: 'pending' | 'active' | 'disabled' | 'error';
  assignmentMode: 'equal' | 'roundRobin' | 'specificUser';
  roundRobin: boolean;
  team?: Types.ObjectId;
  assignedTo?: Types.ObjectId[];
  rrIndex?: number;
  isActive?: boolean;
  isDeleted?: boolean;
  deletedAt?: Date;
  deletedBy?: Types.ObjectId;
  updatedBy?: Types.ObjectId;

  buyingPreference?: LeadBuyingPreference;
  project?: Types.ObjectId;
  category?: Types.ObjectId;
  configuration?: Types.ObjectId[];
  propertyTypeBuy?: Types.ObjectId[];
  preferredState?: Types.ObjectId;
  preferredCity?: Types.ObjectId;
  preferredLocalities?: Types.ObjectId[];
  metaPageDbId?: string;
  googleAdsWebhookKey?: string;
}

export type NewCaptureLead = NewCreatedCaptureLead;

// For query / list filters
export interface QueryFilter {
  search?: string;
  platform?: string;
  interestType?: string;
  status?: string;
  team?: Types.ObjectId;
  assignedTo?: Types.ObjectId;
  sourceId?: string;
  projectId?: string;
  isActive?: string | boolean;
}

export interface ICaptureLead extends ICaptureLeadBase, AuditFields {}

export interface ICaptureLeadDoc extends ICaptureLead, Document {}

export interface ICaptureLeadModel extends IPaginateModel<ICaptureLeadDoc> {}

export type NewCreatedCaptureLead = ICaptureLeadBase &
  Partial<Pick<AuditFields, 'createdBy' | 'updatedBy'>>;
export type UpdateCaptureLeadBody = Partial<ICaptureLead>;

export type PopulatedCaptureLead = {
  _id: Types.ObjectId;
  createdBy: { firstName: string; lastName: string; email: string };
  team?: { name: string };
  name: string;
  interestType: LeadInterestType;
  status?: string;
};
