# armorDB

from models.loots.armor import Armor
from models.heroes.hero import Hero
from models.loots.loot import Loot

from database.databases.lootDB import LootDB


# pour éviter les pb d'import circulaire
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from database.mainDB import MainDB


class ArmorDB(LootDB):

    def __init__(self, db: "MainDB") -> None:
        self.db = db

    def get_armor(self) -> list[Armor]:
        query = "SELECT * FROM loots WHERE types_id = ?"
        values = (5,)

        self.db.sql_query(query, values)

        results = self.db.cursor.fetchall()

        list_return = []
        for result in results:
            list_return.append(self.define_loot(result))

        return list_return

    def define_loot(self, result: list) -> Armor:
        id = result[0]
        title = result[1]
        type = result[2]
        loot_value = result[3]
        value = result[4]
        description = result[5]
        drop_rate = result[6]

        armor = Armor(title, description, type, loot_value, value, drop_rate)
        armor.id = id

        return armor

    def get_armor_by_hero_type(self, hero: Hero) -> list[Armor]:
        return self.get_loots_by_hero_and_loot_type(hero, Loot.ARMOR)
