import { type ProjectDevelopmentStatus } from '@prisma/client';
import { AggregateRoot } from '@modules/shared';

export interface ProjectDevelopmentProps {
  name: string;
  slug: string;
  developer: string;
  developerLogo: string | null;
  totalUnits: number;
  completedUnits: number;
  status: ProjectDevelopmentStatus;
  startDate: Date | null;
  completionDate: Date | null;
  description: string | null;
  amenities: Record<string, unknown> | null;
  masterPlanUrl: string | null;
  latitude: number;
  longitude: number;
  address: string;
  ward: string;
  district: string;
  city: string;
  minPrice: bigint | null;
  maxPrice: bigint | null;
  pricePerM2Range: Record<string, unknown> | null;
  totalArea: number | null;
  buildingCount: number | null;
  floorCount: number | null;
  unitTypes: Record<string, unknown> | null;
  media: Record<string, unknown>[] | null;
  documents: Record<string, unknown>[] | null;
  tags: string[];
  suitableFor: string[];
  whyThisLocation: string | null;
  isVerified: boolean;
  /** Owning DEVELOPER user id; null when not yet assigned (admin-managed). */
  ownerId: string | null;
}

export class ProjectDevelopmentEntity extends AggregateRoot<string> {
  private _name: string;
  private _slug: string;
  private _developer: string;
  private _developerLogo: string | null;
  private _totalUnits: number;
  private _completedUnits: number;
  private _status: ProjectDevelopmentStatus;
  private _startDate: Date | null;
  private _completionDate: Date | null;
  private _description: string | null;
  private _amenities: Record<string, unknown> | null;
  private _masterPlanUrl: string | null;
  private _latitude: number;
  private _longitude: number;
  private _address: string;
  private _ward: string;
  private _district: string;
  private _city: string;
  private _minPrice: bigint | null;
  private _maxPrice: bigint | null;
  private _pricePerM2Range: Record<string, unknown> | null;
  private _totalArea: number | null;
  private _buildingCount: number | null;
  private _floorCount: number | null;
  private _unitTypes: Record<string, unknown> | null;
  private _media: Record<string, unknown>[] | null;
  private _documents: Record<string, unknown>[] | null;
  private _tags: string[];
  private _suitableFor: string[];
  private _whyThisLocation: string | null;
  private _isVerified: boolean;
  private _ownerId: string | null;

  constructor(id: string, props: ProjectDevelopmentProps, createdAt: Date, updatedAt: Date) {
    super(id, createdAt, updatedAt);
    this._name = props.name;
    this._slug = props.slug;
    this._developer = props.developer;
    this._developerLogo = props.developerLogo;
    this._totalUnits = props.totalUnits;
    this._completedUnits = props.completedUnits;
    this._status = props.status;
    this._startDate = props.startDate;
    this._completionDate = props.completionDate;
    this._description = props.description;
    this._amenities = props.amenities;
    this._masterPlanUrl = props.masterPlanUrl;
    this._latitude = props.latitude;
    this._longitude = props.longitude;
    this._address = props.address;
    this._ward = props.ward;
    this._district = props.district;
    this._city = props.city;
    this._minPrice = props.minPrice;
    this._maxPrice = props.maxPrice;
    this._pricePerM2Range = props.pricePerM2Range;
    this._totalArea = props.totalArea;
    this._buildingCount = props.buildingCount;
    this._floorCount = props.floorCount;
    this._unitTypes = props.unitTypes;
    this._media = props.media;
    this._documents = props.documents;
    this._tags = props.tags;
    this._suitableFor = props.suitableFor;
    this._whyThisLocation = props.whyThisLocation;
    this._isVerified = props.isVerified;
    this._ownerId = props.ownerId;
  }

  get name() { return this._name; }
  get slug() { return this._slug; }
  get developer() { return this._developer; }
  get developerLogo() { return this._developerLogo; }
  get totalUnits() { return this._totalUnits; }
  get completedUnits() { return this._completedUnits; }
  get status() { return this._status; }
  get startDate() { return this._startDate; }
  get completionDate() { return this._completionDate; }
  get description() { return this._description; }
  get amenities() { return this._amenities; }
  get masterPlanUrl() { return this._masterPlanUrl; }
  get latitude() { return this._latitude; }
  get longitude() { return this._longitude; }
  get address() { return this._address; }
  get ward() { return this._ward; }
  get district() { return this._district; }
  get city() { return this._city; }
  get minPrice() { return this._minPrice; }
  get maxPrice() { return this._maxPrice; }
  get pricePerM2Range() { return this._pricePerM2Range; }
  get totalArea() { return this._totalArea; }
  get buildingCount() { return this._buildingCount; }
  get floorCount() { return this._floorCount; }
  get unitTypes() { return this._unitTypes; }
  get media() { return this._media; }
  get documents() { return this._documents; }
  get tags() { return this._tags; }
  get suitableFor() { return this._suitableFor; }
  get whyThisLocation() { return this._whyThisLocation; }
  get isVerified() { return this._isVerified; }
  get ownerId() { return this._ownerId; }

  updateDetails(props: Partial<ProjectDevelopmentProps>): void {
    if (props.name !== undefined) this._name = props.name;
    if (props.developer !== undefined) this._developer = props.developer;
    if (props.developerLogo !== undefined) this._developerLogo = props.developerLogo;
    if (props.totalUnits !== undefined) this._totalUnits = props.totalUnits;
    if (props.completedUnits !== undefined) this._completedUnits = props.completedUnits;
    if (props.status !== undefined) this._status = props.status;
    if (props.startDate !== undefined) this._startDate = props.startDate;
    if (props.completionDate !== undefined) this._completionDate = props.completionDate;
    if (props.description !== undefined) this._description = props.description;
    if (props.amenities !== undefined) this._amenities = props.amenities;
    if (props.masterPlanUrl !== undefined) this._masterPlanUrl = props.masterPlanUrl;
    if (props.minPrice !== undefined) this._minPrice = props.minPrice;
    if (props.maxPrice !== undefined) this._maxPrice = props.maxPrice;
    if (props.pricePerM2Range !== undefined) this._pricePerM2Range = props.pricePerM2Range;
    if (props.totalArea !== undefined) this._totalArea = props.totalArea;
    if (props.buildingCount !== undefined) this._buildingCount = props.buildingCount;
    if (props.floorCount !== undefined) this._floorCount = props.floorCount;
    if (props.unitTypes !== undefined) this._unitTypes = props.unitTypes;
    if (props.media !== undefined) this._media = props.media;
    if (props.documents !== undefined) this._documents = props.documents;
    if (props.tags !== undefined) this._tags = props.tags;
    if (props.suitableFor !== undefined) this._suitableFor = props.suitableFor;
    if (props.whyThisLocation !== undefined) this._whyThisLocation = props.whyThisLocation;
    if (props.isVerified !== undefined) this._isVerified = props.isVerified;
    if (props.ownerId !== undefined) this._ownerId = props.ownerId;
    this.updatedAt = new Date();
  }
}
