import type { IndustrialLeaseType, IndustrialListingStatus, IndustrialPropertyType } from '@prisma/client';
import type { IndustrialListingEntity } from '../entities/industrial-listing.entity';

export const INDUSTRIAL_LISTING_REPOSITORY = Symbol('INDUSTRIAL_LISTING_REPOSITORY');

export interface IndustrialListingSearchParams {
  parkId?: string;
  propertyType?: IndustrialPropertyType;
  leaseType?: IndustrialLeaseType;
  status?: IndustrialListingStatus;
  minAreaM2?: number;
  maxAreaM2?: number;
  minPriceUsdM2?: number;
  maxPriceUsdM2?: number;
  query?: string;
  page?: number;
  limit?: number;
}

export interface PaginatedResult<T> {
  data: T[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

export interface IndustrialListingListItem {
  id: string;
  parkId: string;
  parkName: string;
  propertyType: IndustrialPropertyType;
  leaseType: IndustrialLeaseType;
  status: IndustrialListingStatus;
  title: string;
  areaM2: number;
  /** Decimal(18,4) serialised as string by PostgreSQL numeric — use parseFloat() for arithmetic. */
  priceUsdM2: string | null;
  pricingUnit: string | null;
  ceilingHeightM: number | null;
  hasMezzanine: boolean;
  hasOfficeArea: boolean;
  publishedAt: Date | null;
  createdAt: Date;
}

export interface IndustrialListingDetailData {
  id: string;
  parkId: string;
  parkName: string;
  parkSlug: string;
  agentId: string | null;
  sellerId: string;
  propertyType: IndustrialPropertyType;
  leaseType: IndustrialLeaseType;
  status: IndustrialListingStatus;
  title: string;
  description: string | null;
  areaM2: number;
  ceilingHeightM: number | null;
  floorLoadTonM2: number | null;
  columnSpacingM: number | null;
  dockCount: number | null;
  craneCapacityTon: number | null;
  hasMezzanine: boolean;
  hasOfficeArea: boolean;
  officeAreaM2: number | null;
  /** Decimal(18,4) serialised as string — use parseFloat() for arithmetic. */
  priceUsdM2: string | null;
  pricingUnit: string | null;
  /** Decimal(18,4) serialised as string — use parseFloat() for arithmetic. */
  totalLeasePrice: string | null;
  /** Decimal(18,4) serialised as string — use parseFloat() for arithmetic. */
  managementFee: string | null;
  depositMonths: number | null;
  minLeaseYears: number | null;
  maxLeaseYears: number | null;
  leaseExpiry: Date | null;
  availableFrom: Date | null;
  powerCapacityKva: number | null;
  waterSupplyM3Day: number | null;
  media: Record<string, unknown>[] | null;
  viewCount: number;
  inquiryCount: number;
  publishedAt: Date | null;
  createdAt: Date;
  updatedAt: Date;
}

export interface IIndustrialListingRepository {
  findById(id: string): Promise<IndustrialListingEntity | null>;
  findDetailById(id: string): Promise<IndustrialListingDetailData | null>;
  save(entity: IndustrialListingEntity): Promise<void>;
  update(entity: IndustrialListingEntity): Promise<void>;
  search(params: IndustrialListingSearchParams): Promise<PaginatedResult<IndustrialListingListItem>>;
}
