from pyrogram import raw, enums
from ..object import Object


class SentCode(Object):

    def __init__(
        self,
        *,
        type: "enums.SentCodeType",
        phone_code_hash: str,
        next_type: "enums.NextCodeType" = None,
        timeout: int = None,
    ):
        super().__init__()

        self.type = type
        self.phone_code_hash = phone_code_hash
        self.next_type = next_type
        self.timeout = timeout

    @staticmethod
    def _parse(sent_code: raw.types.auth.SentCode) -> "SentCode":
        return SentCode(
            type=enums.SentCodeType(type(sent_code.type)),
            phone_code_hash=sent_code.phone_code_hash,
            next_type=(
                enums.NextCodeType(type(sent_code.next_type))
                if sent_code.next_type
                else None
            ),
            timeout=sent_code.timeout,
        )
