from __future__ import annotations

from sqlalchemy import BigInteger, DateTime, DECIMAL, ForeignKey, String, text
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import Base


class MaterialDemand(Base):
    __tablename__ = "mrp_material_demand"

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
    demand_no: Mapped[str] = mapped_column(String(50))
    sales_order_item_id: Mapped[int] = mapped_column(ForeignKey("so_sales_order_item.id"))
    product_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
    material_item_id: Mapped[int] = mapped_column(ForeignKey("md_item.id"))
    bom_item_id: Mapped[int] = mapped_column(ForeignKey("md_bom_item.id"))
    order_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
    theoretical_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
    planned_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
    available_stock_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
    shortage_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
    suggested_purchase_qty: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
    suggested_purchase_weight_kg: Mapped[float] = mapped_column(DECIMAL(18, 6), server_default=text("0"))
    status: Mapped[str] = mapped_column(String(32))
    generated_at: Mapped[object | None] = mapped_column(DateTime, nullable=True)
    remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
    created_at: Mapped[object] = mapped_column(DateTime)
    updated_at: Mapped[object] = mapped_column(DateTime)
