from pydantic import BaseModel

from src.system_var import constants


class InstEmpCsvUploadViewModel(BaseModel):
    subtitle: str = '施設担当者データCSVアップロード'
    is_verified: bool = False
    is_insert: bool = False
    error_message_list: list[str] = None
    select_function: str = None
    select_table: str = None
    csv_file_name: str = None
    csv_upload_list: list[dict] = None
    json_upload_data: str = None
    result_message_list: list[str] = None
    select_function_message: str = None

    def select_table_message(self):
        return self.__dummy_table() if self.select_table == 'dummy' else self.__real_table()

    def upload_data_columns(self) -> list[str]:
        return self.__inst_emp_columns()

    def is_select_function_empty(self):
        return self.select_function is None or len(self.select_function) == 0

    def is_select_table_empty(self):
        return self.select_table is None or len(self.select_table) == 0

    def is_error_message_list_empty(self):
        return self.error_message_list is None or len(self.error_message_list) == 0

    def csv_data_count(self):
        return 0 if self.csv_upload_list is None else len(self.csv_upload_list)

    def __inst_emp_columns(self) -> list[str]:
        if self.select_function == 'new':
            return constants.NEW_INST_EMP_CSV_LOGICAL_NAMES
        if self.select_function == 'change':
            return constants.CHANGE_INST_CSV_LOGICAL_NAMES
        return []

    def __real_table(self):
        return constants.CSV_REAL_TABLE_NAME

    def __dummy_table(self):
        return constants.CSV_CHANGE_TABLE_NAME
