import enum

from sqlalchemy import Enum, Float, String
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import Base, TimestampMixin, UUIDPKMixin


class SourceKind(str, enum.Enum):
    tpdb = "tpdb"
    stashdb = "stashdb"
    scraper = "scraper"
    porn_app = "porn_app"
    manual = "manual"


class Source(UUIDPKMixin, TimestampMixin, Base):
    __tablename__ = "sources"

    kind: Mapped[SourceKind] = mapped_column(
        Enum(SourceKind, name="source_kind"), nullable=False
    )
    name: Mapped[str] = mapped_column(String(128), nullable=False, unique=True)
    base_url: Mapped[str | None] = mapped_column(String(512))
    auth_secret_ref: Mapped[str | None] = mapped_column(String(128))
    weight: Mapped[float] = mapped_column(Float, nullable=False, default=1.0, server_default="1.0")
