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

export interface ITasksBase extends AuditFields {
  _id?: Types.ObjectId;
  id: Types.ObjectId;
  companyId: Types.ObjectId;
  contactId: Types.ObjectId;
  leadId: Types.ObjectId;
  assignedTo: Types.ObjectId;
  notes: string;
  activityType: 'call' | 'meeting' | 'siteVisit' | 'other';
  activityDate: Date;
  status: 'pending' | 'completed' | 'cancelled' | 'pending';
  customFields?: {
    [key: string]: string | unknown;
  };
  project?: Types.ObjectId;
  property?: Types.ObjectId;
  notifyAt?: Date[];
}

export interface ICallTask extends ITasksBase {
  callStatus: 'scheduled' | 'followUp' | 'reminder';
}
export interface IMeetingTask extends ITasksBase {
  location: string;
}
export interface ISiteVisitTask extends ITasksBase {
  project?: Types.ObjectId;
  property?: Types.ObjectId;
  siteVisitImage?: string;
}
export interface IOtherTask extends ITasksBase {
  activityName: string;
  project: Types.ObjectId;
}

export type ITasks = ICallTask | IMeetingTask | ISiteVisitTask | IOtherTask;

export type ITasksDoc = ITasks & Document;

export interface ITasksModel extends IPaginateModel<ITasksDoc> {}

export type NewCreatedTasks = Partial<ITasks> &
  Partial<Pick<AuditFields, 'createdBy' | 'updatedBy'>>;

export type UpdateTasksBody = Partial<ITasks>;

export type Phone = { countryCode?: number; number?: number };

export type PopulatedTask = {
  _id: Types.ObjectId;
  assignedTo: { firstName: string; lastName: string; email: string; phone: Phone[] };
  createdBy: { firstName: string; lastName: string };
  contactId: {
    firstName?: string;
    lastName?: string;
    name?: string;
    phone?: Phone[];
  };
  leadId: {
    contact: {
      firstName?: string;
      lastName?: string;
      name?: string;
      phone?: Phone[];
    };
    contactDetails: {
      name?: string;
      email?: string;
      phone?: string;
    }

  };
  project?: {
    projectName?: string;
  };
  property?: {
    _id?: Types.ObjectId;
    title?: string;
    address?: string;
  };
  companyId: { name: string, _id: string };
  activityType: string;
  activityDate: Date;
};
