// server/utils/village.ts

export type VillageObjectKind =
  | 'HOUSE'
  | 'FIELD'
  | 'LUMBERJACK'
  | 'QUARRY'
  | 'WELL'
  | 'ROAD'
  | 'FENCE';

export type CropKind = 'BLUEBERRIES' | 'CORN';

// --- Game Economy & Rules ---
export const VILLAGE_GRID_SIZE = { width: 15, height: 15 };

export const ITEM_COSTS: Partial<Record<VillageObjectKind, number>> = {
  HOUSE: 50,
  FIELD: 15,
  ROAD: 5,
  FENCE: 10,
};

export const OBSTACLE_CLEAR_COST: Record<string, number> = {
  ROCK: 20,
  BUSH: 5,
  MUSHROOM: 10,
  DEFAULT: 15, // Fallback cost for untyped obstacles
};

export const PLANTING_COST = 2; // A small, flat cost for seeds

// --- Crop Timings (in milliseconds) ---
export const CROP_GROWTH_TIME: Record<CropKind, number> = {
  BLUEBERRIES: 60 * 60 * 1000, // 1 hour
  CORN: 4 * 60 * 60 * 1000,   // 4 hours
};

/**
 * Checks if a crop is grown based on when it was planted.
 * @param plantedAt The ISO string or Date object when the crop was planted.
 * @param cropType The type of crop.
 * @returns True if the crop has finished growing.
 */
export function isCropGrown(plantedAt: Date | null, cropType: CropKind | null): boolean {
  if (!plantedAt || !cropType) {
    return false;
  }
  const growthTime = CROP_GROWTH_TIME[cropType];
  if (growthTime === undefined) {
    return false;
  }

  return (Date.now() - new Date(plantedAt).getTime()) > growthTime;
}
