from fastapi import Request
from typing import List, Optional


class AddWorktypeForm:
    def __init__(self, request: Request):
        self.request = request
        self.errors: List = []
        self.worktype: Optional[str] = None

    async def load_data(self):
        form = await self.request.form()
        self.worktype = form.get("worktype")

    def is_valid(self):
        if not self.worktype or (len(self.worktype) == 0):
            self.errors.append("WorkType cannot be empty")
        if not self.errors:
            return True
        return False
