import type { OasisType, RegionType } from "./types";
import { getUnitSource } from "./utils";
import type { VillageState } from "./village";


export function resolveMission(V: VillageState, region: RegionType) {
    const mission = region.state.mission;
    if (!mission) {
        return;
    }

    switch (mission.type) {
        case 'pillage':
            if (region.type === 'oasis') {
                resolvePillageOasis(V, region);
            }
            break;
        default:
            throw new Error(`Unknown mission type: "${ mission.type }"`);
    }
}


function resolvePillageOasis(V: VillageState, region: OasisType) {
    const mission = region.state.mission;
    if (!mission) {
        return;
    }

    const unit = getUnitSource('soldier');

    V.resources[region.resource] += mission.unitCount * unit.behavior.caryingCapacity;
    delete region.state.mission;
}
