from __future__ import annotations

from datetime import date

from sqlalchemy import CheckConstraint, Date, ForeignKey, Integer, Numeric, SmallInteger, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.db.base import Base


class BudgetLineQuarter(Base):
    __tablename__ = "budget_line_quarter"
    __table_args__ = (
        CheckConstraint("quarter >= 1 AND quarter <= 4", name="chk_budget_line_quarter_quarter"),
        {"schema": "v3"},
    )

    line_id: Mapped[int] = mapped_column(Integer, ForeignKey("v3.budget_line.id"), primary_key=True)
    quarter: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
    adj_current: Mapped[float | None] = mapped_column(Numeric)
    adj_ssp: Mapped[float | None] = mapped_column(Numeric)
    adj_rf: Mapped[float | None] = mapped_column(Numeric)
    adj_reserve: Mapped[float | None] = mapped_column(Numeric)
    adj_comment: Mapped[str | None] = mapped_column(String)
    target_change: Mapped[float | None] = mapped_column(Numeric)
    base_plan_correction: Mapped[float | None] = mapped_column(Numeric)
    base_plan_correction_comment: Mapped[str | None] = mapped_column(String)
    payment_date: Mapped[date | None] = mapped_column(Date)
    payment_amount: Mapped[float | None] = mapped_column(Numeric)
    payment_amount_ho: Mapped[float | None] = mapped_column(Numeric)
    payment_amount_rf: Mapped[float | None] = mapped_column(Numeric)
    payment_comment: Mapped[str | None] = mapped_column(String)
    payment_act: Mapped[str | None] = mapped_column(String)
    actual_m1: Mapped[float | None] = mapped_column(Numeric)
    actual_m2: Mapped[float | None] = mapped_column(Numeric)
    actual_m3: Mapped[float | None] = mapped_column(Numeric)
    actual_spod: Mapped[float | None] = mapped_column(Numeric)
    transfer_to_q2: Mapped[float | None] = mapped_column(Numeric)
    transfer_to_q3: Mapped[float | None] = mapped_column(Numeric)
    transfer_to_q4: Mapped[float | None] = mapped_column(Numeric)
    transfer_to_economy: Mapped[float | None] = mapped_column(Numeric)
    transfer_delay_acts: Mapped[float | None] = mapped_column(Numeric)
    transfer_delay_procurement: Mapped[float | None] = mapped_column(Numeric)
    transfer_economy_rf: Mapped[float | None] = mapped_column(Numeric)
    transfer_next_comment: Mapped[str | None] = mapped_column(String)
    transfer_far_comment: Mapped[str | None] = mapped_column(String)
    booking_amount: Mapped[float | None] = mapped_column(Numeric)
    plan_revision_eco_change: Mapped[float | None] = mapped_column(Numeric)
    plan_revision_item_adj: Mapped[float | None] = mapped_column(Numeric)
    plan_revision_increase: Mapped[float | None] = mapped_column(Numeric)
    plan_revision_sequester: Mapped[float | None] = mapped_column(Numeric)
    plan_revision_comment: Mapped[str | None] = mapped_column(String)

#     line = relationship("BudgetLine", back_populates="quarters")
