import type { IndustrialParkStatus, VietnamRegion } from '@prisma/client';
import type { IndustrialParkEntity } from '../entities/industrial-park.entity';

export const INDUSTRIAL_PARK_REPOSITORY = Symbol('INDUSTRIAL_PARK_REPOSITORY');

export interface IndustrialParkSearchParams {
  query?: string;
  province?: string;
  region?: VietnamRegion;
  status?: IndustrialParkStatus;
  minAreaHa?: number;
  maxRentUsdM2?: number;
  targetIndustry?: string;
  page?: number;
  limit?: number;
}

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

export interface IndustrialParkListItem {
  id: string;
  name: string;
  nameEn: string | null;
  slug: string;
  developer: string;
  status: IndustrialParkStatus;
  province: string;
  region: VietnamRegion;
  totalAreaHa: number;
  occupancyRate: number;
  remainingAreaHa: number;
  tenantCount: number;
  landRentUsdM2Year: number | null;
  rbfRentUsdM2Month: number | null;
  rbwRentUsdM2Month: number | null;
  targetIndustries: string[];
  latitude: number;
  longitude: number;
}

export interface IndustrialParkDetailData {
  id: string;
  name: string;
  nameEn: string | null;
  slug: string;
  developer: string;
  operator: string | null;
  status: IndustrialParkStatus;
  latitude: number;
  longitude: number;
  address: string;
  district: string;
  province: string;
  region: VietnamRegion;
  totalAreaHa: number;
  leasableAreaHa: number;
  occupancyRate: number;
  remainingAreaHa: number;
  tenantCount: number;
  establishedYear: number | null;
  landRentUsdM2Year: number | null;
  rbfRentUsdM2Month: number | null;
  rbwRentUsdM2Month: number | null;
  managementFeeUsd: number | null;
  infrastructure: Record<string, unknown> | null;
  connectivity: Record<string, unknown> | null;
  incentives: Record<string, unknown> | null;
  targetIndustries: string[];
  existingTenants: Record<string, unknown>[] | null;
  certifications: string[] | null;
  media: Record<string, unknown>[] | null;
  documents: Record<string, unknown>[] | null;
  description: string | null;
  descriptionEn: string | null;
  isVerified: boolean;
  listingCount: number;
  createdAt: Date;
  updatedAt: Date;
}

export interface IndustrialParkStatsData {
  totalParks: number;
  totalAreaHa: number;
  avgOccupancyRate: number;
  totalTenants: number;
  byRegion: { region: string; count: number; avgOccupancy: number }[];
  byStatus: { status: string; count: number }[];
  topProvinces: { province: string; count: number; avgRent: number | null }[];
}

export interface IndustrialMarketData {
  totalParks: number;
  avgOccupancyRate: number;
  avgLandRentUsdM2: number | null;
  avgRbfRentUsdM2: number | null;
  rentByRegion: { region: string; avgLandRent: number | null; avgRbfRent: number | null; parkCount: number }[];
  rentByProvince: { province: string; avgLandRent: number | null; avgRbfRent: number | null; parkCount: number }[];
}

export interface IIndustrialParkRepository {
  findById(id: string): Promise<IndustrialParkEntity | null>;
  findBySlug(slug: string): Promise<IndustrialParkEntity | null>;
  findDetailBySlug(slug: string): Promise<IndustrialParkDetailData | null>;
  findDetailById(id: string): Promise<IndustrialParkDetailData | null>;
  save(entity: IndustrialParkEntity): Promise<void>;
  update(entity: IndustrialParkEntity): Promise<void>;
  search(params: IndustrialParkSearchParams): Promise<PaginatedResult<IndustrialParkListItem>>;
  compareParks(ids: string[]): Promise<IndustrialParkDetailData[]>;
  getStats(): Promise<IndustrialParkStatsData>;
  getMarketData(): Promise<IndustrialMarketData>;
}
