from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field, ConfigDict
from pydantic.alias_generators import to_camel

from persona_models.common import create_uuid


class AuthorizeRequest(BaseModel):
    name: str
    client_id: Optional[str] = None
    client_secret: Optional[str] = None
    scope: Optional[str] = None
    api_key: Optional[str] = None
    api_secret: Optional[str] = None
    token: Optional[str] = None
    server: Optional[str] = None
    port: Optional[int] = None
    username: Optional[str] = None
    password: Optional[str] = None
    use_ssl: Optional[bool] = None
    success_url: Optional[str] = None

    model_config = ConfigDict(
        populate_by_name=True, alias_generator=to_camel, extra="allow"
    )


class Credentials(BaseModel):
    id: str = Field(default_factory=create_uuid)
    name: str | None = None
    project_id: str | None = None
    provider: str
    obtained_at: datetime | None = None
    valid_until: datetime | None = None
    data: dict = Field(default_factory=dict)
    client_id: Optional[str] = None
    client_secret: Optional[str] = None
    api_key: Optional[str] = None
    api_secret: Optional[str] = None
    token: Optional[str] = None
    active: bool = True
    server: Optional[str] = None
    port: Optional[int] = None
    username: Optional[str] = None
    password: Optional[str] = None
    use_ssl: Optional[bool] = None
    success_url: Optional[str] = None

    model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)
