from typing import Optional

from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base
from sqlalchemy import Boolean, Integer, PrimaryKeyConstraint, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column


class Sector(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "sectors"  # GSectores
    __table_args__ = (
        PrimaryKeyConstraint("id", name="sectors_pkey"),
        UniqueConstraint("tenant_id", "company_id", "key", name="sectors_key_ukey"),
        {"schema": "a76", "extend_existing": True},
    )

    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    key: Mapped[str] = mapped_column(String(8), nullable=False)
    description: Mapped[str] = mapped_column(String(150), nullable=False)
    authorized: Mapped[Optional[bool]] = mapped_column(Boolean, default=False, server_default="false")

    def __repr__(self):
        return f"<Sector(id={self.id}, key={self.key}, description={self.description}, authorized={self.authorized})>"
