from typing import Optional, Annotated

from fastapi import Form

from src.util.sanitize import sanitize
from fastapi import File, UploadFile

from src.model.request.request_base_model import RequestBaseModel


@sanitize
class MasterMainteCsvUpModel(RequestBaseModel):
    csv_file: Optional[Annotated[UploadFile, File()]]
    select_function: Optional[str]
    select_table: Optional[str]
    json_upload_data: Optional[str]

    @classmethod
    def as_form(
        cls,
        ctrl_csv_file: UploadFile = Form(None),
        ctrl_select_function: Optional[str] = Form(None),
        ctrl_select_table: Optional[str] = Form(None),
        ctrl_json_upload_data: Optional[str] = Form(None)
    ):
        return cls(
            csv_file=ctrl_csv_file,
            select_function=ctrl_select_function,
            select_table=ctrl_select_table,
            json_upload_data=ctrl_json_upload_data
        )
