from datetime import datetime
from decimal import Decimal
from typing import Optional

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


class ExchangeRate(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "exchange_rate"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="exchange_rate_pkey"),

        UniqueConstraint(
            "tenant_id", "company_id", "date", name="uq_exchange_rate_date_tenant"
        ),
        {"schema": "a76"},
    )

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

    date: Mapped[datetime] = mapped_column(DateTime)

    value: Mapped[Optional[Decimal]] = mapped_column(DECIMAL(13, 6))

    local_currency: Mapped[Optional[str]] = mapped_column(String(7))
    
    foreign_currency: Mapped[Optional[str]] = mapped_column(String(7))
