from datetime import (
    datetime,
    timedelta,
)
from typing import Optional


class UserUpdateData(object):
    def __init__(
        self,
        user_id,            # type: int
        long_name,          # type: str
        password,           # type: str
        nfc_id_code,        # type: str
        level,              # type: int
        start_date,         # type: str
        end_date,           # type: str
        pay_rate,           # type: float
        status=None,        # type: Optional[int]
    ):
        # type: (...) -> None

        self.user_id = user_id
        self.long_name = long_name
        self.password = password
        self.nfc_id_code = nfc_id_code
        self.level = level
        self.start_date = start_date
        self.end_date = end_date
        self.pay_rate = pay_rate
        self.status = status

    def fill_user_status(self):
        start = datetime.strptime(self.start_date, "%Y-%m-%d")
        now = datetime.now()
        if self.end_date is not None:
            end = datetime.strptime(self.end_date, "%Y-%m-%d")
        else:
            one_day = timedelta(days=1)
            end = now + one_day

        active = False
        if start <= now <= end or int(self.level) >= 30:
            active = True

        self.status = "0" if active else "1"
