# generated by datamodel-codegen:
#   filename:  all.schemas.json

from __future__ import annotations

from enum import Enum
from typing import Any

from pydantic import EmailStr, Field, RootModel
from triton_shared.base import BaseSchema


class Model(RootModel[Any]):
    root: Any


class LoginRequest(BaseSchema):
    email: EmailStr
    password: str = Field(..., min_length=8)
    remember_me: bool | None = Field(False, alias='rememberMe')


class JwtPayload(BaseSchema):
    iss: str = Field(
        ..., description='Issuer, e.g. https://api.triton.boatfix.com', min_length=1
    )
    sub: str = Field(..., description='Subject: user id', min_length=1)
    aud: list[str] = Field(
        ..., description='Audience(s): e.g. triton-frontend, triton-api', min_length=1
    )
    iat: int = Field(..., description='Issued-at (epoch seconds)', ge=0)
    exp: int = Field(..., description='Expires (epoch seconds)', ge=0)
    nbf: int | None = Field(None, description='Not before (epoch seconds)', ge=0)
    jti: str | None = Field(None, description='JWT ID (for revocation/blacklist)')


class TokenErrorCode(Enum):
    TOKEN_INVALID = 'token_invalid'
    TOKEN_EXPIRED = 'token_expired'
    TOKEN_NOT_YET_VALID = 'token_not_yet_valid'
    TOKEN_REVOKED = 'token_revoked'
    TOKEN_AUDIENCE_MISMATCH = 'token_audience_mismatch'
    TOKEN_ISSUER_MISMATCH = 'token_issuer_mismatch'
    TOKEN_ROLE_MISMATCH = 'token_role_mismatch'
    TOKEN_INVALID_SUBJECT = 'token_invalid_subject'
    TOKEN_TENANT_MISMATCH = 'token_tenant_mismatch'
    TOKEN_MISSING = 'token_missing'


class Role(Enum):
    ADMIN = 'admin'
    INSURER = 'insurer'
    BUILDER = 'builder'


class Membership(BaseSchema):
    tenant_id: str = Field(..., alias='tenantId', min_length=1)
    role: Role


class UserPublic(BaseSchema):
    id: str = Field(..., min_length=1)
    email: EmailStr
    first_name: str | None = Field(None, alias='firstName')
    last_name: str | None = Field(None, alias='lastName')
    tenants: list[Membership] = Field(..., min_length=0)


class LoginResponse(BaseSchema):
    user: UserPublic
