from __future__ import annotations

from datetime import datetime

from sqlalchemy import DateTime, ForeignKey, Index, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.db.base import Base


class BudgetLine(Base):
    __tablename__ = "budget_line"
    __table_args__ = (
        Index("ix_v3_budget_line_form_item", "budget_form_id", "expense_item_id"),
        Index("ix_v3_budget_line_vsp", "vsp_id"),
        {"schema": "v3"},
    )

    id: Mapped[int] = mapped_column(primary_key=True)
    budget_form_id: Mapped[int] = mapped_column(Integer, ForeignKey("v3.budget_form.id"))
    expense_item_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("v3.expense_item.id"))
    name: Mapped[str | None] = mapped_column(String)
    internal_order: Mapped[str | None] = mapped_column(String)
    vsp_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("v3.vsp.id"))
    project_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("v3.project.id"))
    justification: Mapped[str | None] = mapped_column(String)
    created_by: Mapped[int | None] = mapped_column(Integer, ForeignKey("v3.app_user.id"))
    created_at: Mapped[datetime | None] = mapped_column(DateTime, default=None)
    updated_by: Mapped[int | None] = mapped_column(Integer, ForeignKey("v3.app_user.id"))
    updated_at: Mapped[datetime | None] = mapped_column(DateTime, default=None)
    direction: Mapped[str | None] = mapped_column(String)

#     budget_form = relationship("BudgetForm", back_populates="budget_lines")
#     expense_item = relationship("ExpenseItem", back_populates="budget_lines")
#     vsp = relationship("Vsp", back_populates="budget_lines")
#     project = relationship("Project", back_populates="budget_lines")

#     ckk = relationship("Ckk", uselist=False)
#     collegial_approval = relationship("CollegialApproval", uselist=False)
#     contract_detail = relationship("ContractDetail", uselist=False)
#     contract_summary = relationship("ContractSummary", uselist=False)
#     plan = relationship("Plan", uselist=False)
#     reserve = relationship("Reserve", uselist=False)
#     allocation = relationship("Allocation", uselist=False)

#     quarters: Mapped[list["BudgetLineQuarter"]] = relationship("BudgetLineQuarter", back_populates="line")  # type: ignore
#     sequestration_records: Mapped[list["Sequestration"]] = relationship("Sequestration", back_populates="budget_line")  # type: ignore
#     booking_records: Mapped[list["Booking"]] = relationship("Booking", back_populates="budget_line")  # type: ignore
#     rent_details: Mapped[list["RentDetail"]] = relationship("RentDetail", back_populates="budget_line")  # type: ignore
#     security_details: Mapped[list["SecurityDetail"]] = relationship("SecurityDetail", back_populates="budget_line")  # type: ignore
#     utility_details: Mapped[list["UtilityDetail"]] = relationship("UtilityDetail", back_populates="budget_line")  # type: ignore
