from typing import Optional

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


class PermissionRuleOct(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "permission_rule_oct"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="permission_rule_oct_pkey"),
        UniqueConstraint(
            "tenant_id",
            "company_id",
            "permission",
            name="permission_rule_oct_permission_tenant_ukey",
        ),
        {"schema": "a76"},
    )
    id: Mapped[int] = mapped_column(Integer, primary_key=True)

    permission: Mapped[str] = mapped_column(String(20))
    start_date: Mapped[Optional[int]] = mapped_column()
    end_date: Mapped[Optional[int]] = mapped_column()
    sector: Mapped[Optional[str]] = mapped_column(String(8))
    system: Mapped[Optional[str]] = mapped_column(String(5))
