from typing import Optional


class UserDto(object):

    def __init__(
        self,
        user_id,                    # type: int
        level,                      # type: int
        user_name,                  # type: str
        long_name,                  # type: str
        status,                     # type: int
        admission_date=None,        # type: Optional[str]
        termination_date=None,      # type: Optional[str]
        password=None,              # type: Optional[str]
        fingerprint_minutiae=None,  # type: Optional[str]
        nfc_uuid=None,              # type: Optional[str]
    ):
        # type: (...) -> None

        self.user_id = user_id
        self.level = int(level)
        self.user_name = user_name
        self.long_name = long_name
        self.status = int(status) if status is not None else status
        self.admission_date = admission_date
        self.termination_date = termination_date
        self.password = password
        self.fingerprint_minutiae = fingerprint_minutiae
        self.nfc_uuid = nfc_uuid

    def authenticate_response(
        self,   # type: UserDto
    ):
        # type: (...) -> bytes

        user_params_data = "{}\0{}\0{}\0{}\0{}\0{}".format(
            self.level,
            self.user_name,
            self.long_name,
            self.status,
            self.admission_date or "",
            self.termination_date or "",
        )
        return user_params_data.encode("utf-8")

    def authenticate_nfc_response(
        self,   # type: UserDto
    ):
        # type: (...) -> bytes

        user_params_data = "{}\0{}\0{}\0{}\0{}\0{}\0{}".format(
            self.user_id,
            self.level,
            self.user_name,
            self.long_name,
            self.status,
            self.admission_date or "",
            self.termination_date or "",
        )
        return user_params_data.encode("utf-8")

    def get_info_response(
        self,   # type: UserDto
    ):
        # type: (...) -> str

        user_attributes = (
            'UserId="{0}" '
            'UserName="{1}" '
            'LongName="{2}" '
            'Level="{3}" '
            'Status="{4}"'
        ).format(
            self.user_id,
            self.user_name,
            self.long_name,
            self.level,
            self.status,
        )

        if self.admission_date:
            user_attributes += ' AdmissionDate="{}"'.format(self.admission_date)
        if self.termination_date:
            user_attributes += ' TerminationDate="{}"'.format(self.termination_date)

        user_event_data = "<user {}/>".format(user_attributes)
        return user_event_data
