from typing import Optional

from sqlalchemy import DateTime, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column

from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base

class OctavePermission(Base, TenantScopedMixin, TimestampMixin):
    """
    Permisos para la Regla Octava.
    Paridad: GPermisoReglaOct (Clarion SCAII).
    """

    __tablename__ = "permission_rule_octave"
    __table_args__ = (
        UniqueConstraint(
            "tenant_id",
            "company_id",
            "permission",
            name="uq_permissions_rule_octave_permission",
        ),
        {"schema": "a76"},
    )

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)

    permission: Mapped[str] = mapped_column(String(20), nullable=False) # PERMISO
    start_date: Mapped[Optional[DateTime]] = mapped_column(DateTime())  # FECHAINICIO
    end_date: Mapped[Optional[DateTime]] = mapped_column(DateTime())    # FECHAFINAL
    sector: Mapped[Optional[str]] = mapped_column(String(8))            # SECTOR
    system: Mapped[Optional[str]] = mapped_column(String(5))            # SISTEMA
