from src.logging.get_logger import get_logger
from src.model.db.hdke_tbl import HdkeTblModel
from src.repositories.base_repository import BaseRepository

logger = get_logger('日付テーブル取得')


class HdkeTblRepository(BaseRepository):
    FETCH_SQL = "SELECT bch_actf, dump_sts_kbn FROM src05.hdke_tbl"

    def fetch_all(self) -> list[HdkeTblModel]:
        try:
            self._database.connect()
            query = self.FETCH_SQL
            result = self._database.execute_select(query)
            models = [HdkeTblModel(**r) for r in result]
            return models
        except Exception as e:
            logger.exception(f"DB Error : Exception={e}")
            raise e
        finally:
            self._database.disconnect()
