//////////////////////////////////////////////////////////////////////////////
// This file is part of the Journey MMORPG client                           //
// Copyright © 2015-2016 Daniel Allendorf                                   //
//                                                                          //
// This program is free software: you can redistribute it and/or modify     //
// it under the terms of the GNU Affero General Public License as           //
// published by the Free Software Foundation, either version 3 of the       //
// License, or (at your option) any later version.                          //
//                                                                          //
// This program is distributed in the hope that it will be useful,          //
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
// GNU Affero General Public License for more details.                      //
//                                                                          //
// You should have received a copy of the GNU Affero General Public License //
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    //
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "BodyDrawInfo.h"
#include "EquipSlot.h"

#include "../../Graphics/Texture.h"
#include "../../Template/EnumMap.h"

#include <unordered_map>

namespace jrc
{
    class Clothing
    {
    public:
        static constexpr int32_t TOP_DEFAULT_ID = 1042399;
        static constexpr int32_t BOTTOM_DEFAULT_ID = 1060026;

        enum Layer
        {
            CAPE, SHOES, PANTS, TOP, MAIL, MAILARM,
            EARRINGS, FACEACC, EYEACC, PENDANT, BELT, MEDAL, RING,
            CAP, CAP_BELOW_BODY, CAP_OVER_HAIR,
            GLOVE, WRIST, GLOVE_OVER_HAIR, WRIST_OVER_HAIR, GLOVE_OVER_BODY, WRIST_OVER_BODY,
            SHIELD, BACKSHIELD, SHIELD_BELOW_BODY, SHIELD_OVER_HAIR,
            WEAPON, BACKWEAPON, WEAPON_BELOW_ARM, WEAPON_BELOW_BODY,
            WEAPON_OVER_HAND, WEAPON_OVER_BODY, WEAPON_OVER_GLOVE,
            PANTS_DEFAULT, TOP_DEFAULT,
            NUM_LAYERS
        };

        // Construct a new equip.
        Clothing(int32_t itemid, const BodyDrawinfo& drawinfo);

        // Draw the equip.
        void draw(Stance::Id stance, Layer layer, uint8_t frame, const DrawArgument& args) const;
        // Check if a part of the equip lies on the specified layer while in the specified stance.
        bool contains_layer(Stance::Id stance, Layer layer) const;

        // Return wether the equip is invisble.
        bool is_transparent() const;
        // Return wether this equip uses twohanded stances.
        bool is_twohanded() const;
        // Return the item id.
        int32_t get_id() const;
        // Return the equip slot for this cloth.
        Equipslot::Id get_eqslot() const;
        // Return the standing stance to use while equipped.
        Stance::Id get_stand() const;
        // Return the walking stance to use while equipped.
        Stance::Id get_walk() const;
        // Return the vslot, used to distinguish some layering types.
        const std::string& get_vslot() const;

    private:
        EnumMap<Stance::Id, EnumMap<Layer, std::unordered_multimap<uint8_t, Texture>, NUM_LAYERS>> stances;
        int32_t itemid;
        Equipslot::Id eqslot;
        Stance::Id walk;
        Stance::Id stand;
        std::string vslot;
        bool twohanded;
        bool transparent;


        static const std::unordered_map<std::string, Layer> sublayernames;
    };
}
