# monsterDB

from models.heroes.monster import Monster

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

if TYPE_CHECKING:
    from database.mainDB import MainDB


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

    def get_all_monsters(self) -> list[Monster]:
        query = "SELECT * FROM monsters WHERE types_id IN (?, ?, ?, ?, ?)"
        values = (
            Monster.BEAST,
            Monster.HUMANOID,
            Monster.UNDEAD,
            Monster.DRAGON,
            Monster.ELEMENTAL,
        )

        self.db.sql_query(query, values)

        results = self.db.cursor.fetchall()

        monsters = []
        for result in results:
            monsters.append(self.define_monster(result))

        return monsters

    def define_monster(self, result: list) -> Monster:
        id = result[0]
        title = result[1]
        types_id = result[2]
        health_points = result[3]
        attack_power = result[4]
        defense = result[5]
        description = result[6]

        monster = Monster(
            title, description, health_points, attack_power, defense, types_id
        )

        monster.id = id

        return monster
