<?php

namespace App\Constants;

class ItemMasks
{
    public const OTHER = 0;
    public const WEAPON = 1;
    public const HELMET = 2;
    public const NECKLACE = 4;
    public const ROBE = 8;
    public const CHEST = 16;
    public const BELT = 32;
    public const LEG = 64;
    public const FEET = 128;
    public const ARMS = 256;
    public const RING = 1536;
    public const FLYING_MOUNT = 4096;
    public const FASHION_CHEST = 8192;
    public const FASHION_LEG = 16384;
    public const FASHION_FEET = 32768;
    public const FASHION_ARMS = 65536;
    public const HEAVEN_BOOK = 262144;
    public const CHAT_SMILEY = 524288;
    public const CHARM_HP = 1048576;
    public const CHARM_MP = 2097152;

    public const ALL = [
        self::OTHER => 'Other',
        self::WEAPON => 'Weapons',
        self::HELMET => 'Helmet',
        self::NECKLACE => 'Necklace',
        self::ROBE => 'Robe',
        self::CHEST => 'Chest',
        self::BELT => 'Belt',
        self::LEG => 'Leg',
        self::FEET => 'Feet',
        self::ARMS => 'Arms',
        self::RING => 'Ring',
        self::FLYING_MOUNT => 'Flying Mount',
        self::FASHION_CHEST => 'Fashion Chest',
        self::FASHION_LEG => 'Fashion Leg',
        self::FASHION_FEET => 'Fashion Feet',
        self::FASHION_ARMS => 'Fashion Arms',
        self::HEAVEN_BOOK => 'Heaven Book/Tome',
        self::CHAT_SMILEY => 'Chat Smiley',
        self::CHARM_HP => 'HP Charm',
        self::CHARM_MP => 'MP Charm',
    ];

    public const GROUPED = [
        'Other' => [
            self::OTHER => 'Other',
        ],
        'Weapons' => [
            self::WEAPON => 'Weapons',
        ],
        'Equipment' => [
            self::HELMET => 'Helmet',
            self::CHEST => 'Chest',
            self::LEG => 'Leg',
            self::FEET => 'Feet',
            self::ARMS => 'Arms',
            self::ROBE => 'Robe',
        ],
        'Fashion' => [
            self::FASHION_CHEST => 'Chest',
            self::FASHION_LEG => 'Leg',
            self::FASHION_FEET => 'Feet',
            self::FASHION_ARMS => 'Arms',
        ],
        'Accessories' => [
            self::RING => 'Ring',
            self::NECKLACE => 'Necklace',
            self::BELT => 'Belt',
        ],
        'Charms' => [
            self::CHARM_HP => 'HP',
            self::CHARM_MP => 'MP',
        ],
        'Misc' => [
            self::FLYING_MOUNT => 'Flying Mount',
            self::HEAVEN_BOOK => 'Heaven Book/Tome',
            self::CHAT_SMILEY => 'Chat Smiley',
        ],
    ];

    public static function getName(int $mask): string
    {
        return self::ALL[$mask] ?? 'Unknown';
    }

    public static function getAll(): array
    {
        return self::ALL;
    }

    public static function getGrouped(): array
    {
        return self::GROUPED;
    }

    public static function getForSelect(): array
    {
        $options = [];
        foreach (self::GROUPED as $group => $items) {
            foreach ($items as $value => $label) {
                $options[] = [
                    'value' => $value,
                    'label' => $label,
                    'group' => $group,
                ];
            }
        }
        return $options;
    }
}
