from collections import OrderedDict

from pydantic import BaseModel

from src.model.db.pharmacy_product_master import PharmacyProductMasterModel
from src.model.db.wholesaler_master import WholesalerMasterModel
from src.system_var import environment


class BioViewModel(BaseModel):
    subtitle: str = '生物由来検索一覧'
    user_id: str
    whs_models: list[WholesalerMasterModel]
    phm_models: list[PharmacyProductMasterModel]
    search_data_max_length: int = environment.BIO_SEARCH_RESULT_MAX_COUNT
    excel_max_lines: str = str(environment.BIO_EXCEL_RESULT_MAX_COUNT)

    def display_wholesaler_names(self):
        display_names = [
            f'{whs_model.rec_whs_cd}-{whs_model.rec_whs_sub_cd}:{whs_model.name or ""}'
            for whs_model in self.whs_models
        ]
        return display_names

    def display_org_kbn(self):
        return OrderedDict(
            {
                '': '',
                'J': 'JD-NET',
                'N': 'NHI',
                'H': '手入力'
            }
        )

    def display_data_kbn(self):
        return OrderedDict(
            {
                '': '',
                '0': '正常',
                '1': 'ロットエラー',
                '3': 'ロット不明',
                '9': 'エラー（解消済み）',
                '2': '除外'
            }
        )
