import big from './assets/characters/big.jpg';
import ninja from './assets/characters/ninja.jpg';
import nurse from './assets/characters/nurse.jpg';
import police from './assets/characters/police.jpg';
import runner from './assets/characters/runner.jpg';

import boss from './assets/enemies/boss.jpg';
import crow from './assets/enemies/crow.jpg';
import dog from './assets/enemies/dog.jpg';
import spider from './assets/enemies/spider.jpg';
import zombie from './assets/enemies/zombie.jpg';

import fuel from './assets/items/fuel.jpg';
import heal from './assets/items/heal.jpg';
import keys from './assets/items/keys.jpg';
import planks from './assets/items/planks.jpg';

import assaultRifle from './assets/weapons/assault_rifle.jpg';
import axe from './assets/weapons/axe.jpg';
import crossbow from './assets/weapons/crossbow.jpg';
import grenade from './assets/weapons/grenade.jpg';
import knife from './assets/weapons/knife.jpg';
import pistol from './assets/weapons/pistol.jpg';
import rocketLauncher from './assets/weapons/rocket_launcher.jpg';
import slingshot from './assets/weapons/slingshot.jpg';
import shotgun from './assets/weapons/shotgun.jpg';

export const ItemType = {
    CHAR_BIG: big,
    CHAR_NINJA: ninja,
    CHAR_NURSE: nurse,
    CHAR_POLICE: police,
    CHAR_RUNNER: runner,

    ENEMY_BOSS: boss,
    ENEMY_CROW: crow,
    ENEMY_DOG: dog,
    ENEMY_SPIDER: spider,
    ENEMY_ZOMBIE: zombie,

    ITEM_FUEL: fuel,
    ITEM_HEALING_KIT: heal,
    ITEM_KEYS: keys,
    ITEM_PLANKS: planks,

    WEAPON_ASSAULT_RIFLE: assaultRifle,
    WEAPON_AXE: axe,
    WEAPON_CROSSBOW: crossbow,
    WEAPON_GRENADE: grenade,
    WEAPON_KNIFE: knife,
    WEAPON_PISTOL: pistol,
    WEAPON_ROCKET_LAUNCHER: rocketLauncher,
    WEAPON_SLINGSHOT: slingshot,
    WEAPON_SHOTGUN: shotgun,
} as const;

type ItemTypeType = typeof ItemType;
type ImageKey = keyof ItemTypeType;
export type ItemTypeImage = ItemTypeType[ImageKey];

export default class Item {
    constructor(public readonly type: ItemTypeImage) {
    }

    get isPickable() {
        return this.isItem || this.isWeapon;
    }

    get isEnemy() {
        return [
            ItemType.ENEMY_BOSS,
            ItemType.ENEMY_CROW,
            ItemType.ENEMY_DOG,
            ItemType.ENEMY_SPIDER,
            ItemType.ENEMY_ZOMBIE,
        ].includes(this.type);
    }

    get isFlyingEnemy() {
        return this.type === ItemType.ENEMY_CROW;
    }

    get isItem() {
        return [
            ItemType.ITEM_FUEL,
            ItemType.ITEM_HEALING_KIT,
            ItemType.ITEM_KEYS,
            ItemType.ITEM_PLANKS,
        ].includes(this.type);
    }

    get isWeapon() {
        return this.isMeleeWeapon || this.isRangedWeapon || [
            ItemType.WEAPON_GRENADE,
            ItemType.WEAPON_ROCKET_LAUNCHER,
        ].includes(this.type);
    }

    get isMeleeWeapon() {
        return [
            ItemType.WEAPON_AXE,
            ItemType.WEAPON_KNIFE,
            ItemType.ITEM_PLANKS,
        ].includes(this.type);
    }

    get isRangedWeapon() {
        return [
            ItemType.WEAPON_ASSAULT_RIFLE,
            ItemType.WEAPON_CROSSBOW,
            ItemType.WEAPON_PISTOL,
            ItemType.WEAPON_SLINGSHOT,
            ItemType.WEAPON_SHOTGUN,
        ].includes(this.type);
    }

    get isSpendingWeapon() {
        return (
            this.type === ItemType.ITEM_PLANKS ||
            (this.type !== ItemType.WEAPON_SLINGSHOT && this.isRangedWeapon)
        );
    }

    get isBoss() {
        return this.type === ItemType.ENEMY_BOSS;
    }

    get isConsumable() {
        return [
            ItemType.ITEM_PLANKS,
            ItemType.WEAPON_GRENADE,
        ].includes(this.type);
    }

    toString() {
        return Object.entries(ItemType).find(t => t[1] === this.type)?.[0];
    }
}
