import type { Hex } from "./hexgrid";


export interface Point {
    x: number;
    y: number;
}


export type GameTab = 'village' | 'resources' | 'world';


export interface CostType {
    wood: number;
    stone: number;
    iron: number;
    food: number;
}


export type ProductionType = CostType;


export interface ResourcesType extends CostType {
    culture: number;
}


export interface BuildingSource {
    name: string;
    type: string;
    autoBuilt?: boolean;
    unique?: boolean;
    maxLevel: number;
    requiredTownhallLevel: number;
    cost: (level: number) => CostType;
    timeToBuild: (level: number) => number;
    behavior: {
        production?: Function;
        storage?: Function;
        units?: {
            type: string;
            recruitmentTime: Function;
        };
        constructionTimeReductionPerLevel?: number;
        triggers?: {
            onLevelUp?: Function;
        };
    };
}


export interface BuildingType extends BuildingSource {
    id: number;
    level: number;
    tile: Hex;
    state: {
        upgrade: {
            isUpgrading: boolean,
            remainingTime: number;
        }
        recruitment?: {
            count: number;
            elapsedTime: number;
        };
    };
}


export interface UnitType {
    type: string;
    name: string;
    cost: CostType;
    behavior: {
        caryingCapacity: number;
        foodIntakePerMinute: number;
        culturePerMinute?: number;
    }
}


export interface MissionType {
    type: 'pillage' | 'clear';
    unitType: string;
    unitCount: number;
    remainingTime: number;
    repeat?: boolean;
}


export enum WORLDMAP_TYPES {
    EMPTY,
    OASIS,
    BOURGADE,
}


interface BaseRegionType {
    id: number;
    type: WORLDMAP_TYPES;
    distance: number;
}


export interface EmptyRegionType extends BaseRegionType {
    type: WORLDMAP_TYPES.EMPTY;
}


export interface OasisType extends BaseRegionType {
    type: WORLDMAP_TYPES.OASIS;
    resource: keyof CostType;
    strength: number;
    state: {
        cleared: boolean;
        mission?: MissionType;
    };
}


export interface BourgadeType extends BaseRegionType {
    type: WORLDMAP_TYPES.BOURGADE;
}


export type RegionType = EmptyRegionType | OasisType | BourgadeType;


export interface HeroType {
    id: number;
    name: string;
}


export interface QuestType {
    id: number;
    duration: number;
    reward: ResourcesType;
    level: number;
    started: boolean;
    hero?: number;
    remainingTime?: number;
}
