import type { BuildingSource } from "./types";
import type { VillageState } from "./village";


export function getTimeToBuild(V: VillageState, building: BuildingSource, level: number): number {
    const townhall = V.buildings.find(b => b.type === 'townhall');
    if (!townhall) {
        throw new Error("Unable to find the Town hall");
    }

    const reduction = townhall.level * (townhall.behavior.constructionTimeReductionPerLevel || 0);
    const baseBuildingTime = building.timeToBuild(level) * 1000;
    return baseBuildingTime - (baseBuildingTime * reduction);
}
