import { WORLDMAP_TYPES } from "../types";
import { assert, getRemainingUnitCount } from "../utils";
import type { VillageState } from "../village";


export default function clear(
    V: VillageState, regionIndex: number, soldiersCount: number
) {
    if (soldiersCount > getRemainingUnitCount(V, 'soldier')) {
        return false;
    }

    const region = V.worldmap[regionIndex];
    assert(region.type === WORLDMAP_TYPES.OASIS);

    if (region.state.mission) {
        return false;
    }

    region.state.mission = {
        type: 'clear',
        unitType: 'soldier',
        unitCount: soldiersCount,
        remainingTime: region.distance * 10 * 1000,
    };

    return true;
}
