"""Currency model — multi-currency support for ERP."""

from __future__ import annotations

import uuid

from sqlalchemy import Boolean, Index, String, UniqueConstraint
from sqlalchemy.dialects.postgresql import UUID as PGUUID
from sqlalchemy.orm import Mapped, mapped_column

from app.core.db import Base, TenantMixin


class Currency(Base, TenantMixin):
    """Currency entity — e.g. EUR, USD, GBP."""

    __tablename__ = "currencies"
    __table_args__ = (
        UniqueConstraint("tenant_id", "code", name="uq_currency_tenant_code"),
        Index("ix_currencies_tenant_code", "tenant_id", "code"),
        Index("ix_currencies_tenant_default", "tenant_id", "is_default"),
    )

    id: Mapped[uuid.UUID] = mapped_column(
        PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
    )
    code: Mapped[str] = mapped_column(String(3), nullable=False)
    name: Mapped[str] = mapped_column(String(50), nullable=False)
    symbol: Mapped[str] = mapped_column(String(5), nullable=False)
    is_default: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
