import { Document, Types } from 'mongoose';

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

export interface IProjectBase {
  projectName: string;
  normalizedName: string;
  description?: string;
  type?: Types.ObjectId;
  isSystemGenerated: boolean;
  searchCount: number;
  propertyType: Types.ObjectId;
  locality: Types.ObjectId;
  city: Types.ObjectId;
  state: Types.ObjectId;
  status: string;
  pincode: number;
  possessionDate: Date;
  pricePerSqYard: number;
  landmark: string;
  amenities: Types.ObjectId[];
  reraId: string;
  companyId: Types.ObjectId;
  team?: Types.ObjectId | null;
  isDraft: boolean;
  creationMethod: string;
  mediaUrls: string[];
  subCategory?: Types.ObjectId;
  hasBlockLayout?: boolean;
  visibleToUsers?: Types.ObjectId[];
  visibleToTeams?: Types.ObjectId[];
  isPublicVisibility?: boolean;
}

export interface IProject extends IProjectBase, AuditFields {}

export interface IProjectDoc extends IProject, Document {
  timelines?: Types.DocumentArray<Types.ObjectId>;
}

export interface IProjectModel extends IPaginateModel<IProjectDoc> {}

export type NewCreatedProject = IProjectBase &
  Partial<Pick<AuditFields, 'createdBy' | 'updatedBy'>>;
export type UpdateProjectBody = Partial<IProject>;

export interface IProjectFilter {
  search?: string;
  propertyType?: Types.ObjectId | string;
  creationMethod?: string;
  createdBy?: Types.ObjectId | string;
  limit?: number;
}

export interface IUnitBase {
  project: Types.ObjectId;
  propertyType: Types.ObjectId;
  size: number;
  price: number;
  unitNumber: string;
  status: string;
  floor?: number | null;
  block?: string | null;
  customFields?: Record<string, unknown> | null;
}
export interface IUnit extends IUnitBase, AuditFields {}
export interface IUnitDoc extends IUnit, Document {}
export interface IUnitModel extends IPaginateModel<IUnitDoc> {}

export type NewCreatedUnit = IUnitBase &
  Partial<Pick<AuditFields, 'createdBy' | 'updatedBy'>>;
export type UpdateUnitBody = Partial<IUnit>;

export interface IUnitFilter {
  project?: Types.ObjectId | string;
  propertyType?: Types.ObjectId | string;
  status?: string;
  statuses?: string;
  createdBy?: Types.ObjectId | string;
  limit?: number;
  search?: string;
}

export interface PopulatedProject {
  projectName: string;
  propertyType: {
    name: string;
  };
  status: string;
}
