from dataclasses import dataclass, field
from typing import Any, Self

__all__ = ["SignInResult"]


@dataclass(frozen=True, slots=True)
class SignInResult:
    succeeded: bool = field(default=False)
    is_locked_out: bool = field(default=False)
    is_not_allowed: bool = field(default=False)
    requires_two_factor: bool = field(default=False)
    response: Any | None = field(default=None)

    @classmethod
    def success(cls, response: Any | None = None) -> Self:
        return cls(succeeded=True, response=response)

    @classmethod
    def locked_out(cls, response: Any | None = None) -> Self:
        return cls(is_locked_out=True, response=response)

    @classmethod
    def not_allowed(cls, response: Any | None = None) -> Self:
        return cls(is_not_allowed=True, response=response)

    @classmethod
    def two_factor_required(cls, response: Any | None = None) -> Self:
        return cls(requires_two_factor=True, response=response)

    @classmethod
    def failed(cls, response: Any | None = None) -> Self:
        return cls(response=response)

    def __str__(self) -> str:
        if self.is_locked_out:
            return "Locked out"
        if self.is_not_allowed:
            return "Not Allowed"
        if self.requires_two_factor:
            return "Requires Two-Factor"
        if self.succeeded:
            return "Succeeded"
        return "Failed"
