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

export interface ICPPhone {
  countryCode: number;
  number: number;
  isPrimary?: boolean;
}

export interface ICPCompanyBase {
  companyName: string;
  website?: string;
  address?: string;
  city?: string;
  state?: string;
  country?: string;
  baseCommissionRate?: number;
  notes?: string;
  status: 'Active' | 'Inactive';
  company: Types.ObjectId;
}

export interface ICPCompany extends ICPCompanyBase, AuditFields {}

export interface ICPCompanyDoc extends ICPCompany, Document {}

export interface ICPCompanyModel extends IPaginateModel<ICPCompanyDoc> {}

export type NewCPCompany = ICPCompanyBase &
  Partial<Pick<AuditFields, 'createdBy' | 'updatedBy'>>;

export type UpdateCPCompanyBody = Partial<Omit<ICPCompanyBase, 'company'>>;

export interface ICPContactBase {
  firstName: string;
  lastName: string;
  phone: ICPPhone[];
  email?: string;
  isPrimary: boolean;
  status: 'Active' | 'Inactive';
  cpCompany: Types.ObjectId;
  company: Types.ObjectId;
}

export interface ICPContact extends ICPContactBase, AuditFields {}

export interface ICPContactDoc extends ICPContact, Document {}

export interface ICPContactModel extends IPaginateModel<ICPContactDoc> {}

export type NewCPContact = ICPContactBase &
  Partial<Pick<AuditFields, 'createdBy' | 'updatedBy'>>;

export type UpdateCPContactBody = Partial<
  Omit<ICPContactBase, 'cpCompany' | 'company'>
>;

export interface ICPPaymentBase {
  cpCompany: Types.ObjectId;
  company: Types.ObjectId;
  paymentDate: Date;
  amountPaid: number;
  notes?: string;
}

export interface ICPPayment extends ICPPaymentBase, AuditFields {}

export interface ICPPaymentDoc extends ICPPayment, Document {}

export interface ICPPaymentModel extends IPaginateModel<ICPPaymentDoc> {}

export type NewCPPayment = ICPPaymentBase &
  Partial<Pick<AuditFields, 'createdBy' | 'updatedBy'>>;

export interface QueryFilter {
  search?: string;
  company?: string;
  companyId?: string;
  status?: string;
  cpCompany?: string;
  [key: string]: unknown;
}
