"""Forgejo connection model storing organization-level Forgejo instance metadata."""

from __future__ import annotations

from datetime import datetime
from uuid import UUID, uuid4

from sqlmodel import Field

from app.core.time import utcnow
from app.models.base import QueryModel

RUNTIME_ANNOTATION_TYPES = (datetime,)


class ForgejoConnection(QueryModel, table=True):
    """Configured Forgejo instance connection and authentication settings."""

    __tablename__ = "forgejo_connections"  # pyright: ignore[reportAssignmentType]

    id: UUID = Field(default_factory=uuid4, primary_key=True)
    organization_id: UUID = Field(foreign_key="organizations.id", index=True)
    name: str
    base_url: str
    token: str | None = Field(default=None)
    token_last_eight: str | None = Field(default=None)
    active: bool = Field(default=True)
    created_at: datetime = Field(default_factory=utcnow)
    updated_at: datetime = Field(default_factory=utcnow)
