from datetime import datetime

from sqlalchemy import Boolean, DateTime, Float, String
from sqlalchemy.orm import Mapped, mapped_column

from app.db.session import Base


class ProcessCostRule(Base):
    __tablename__ = "process_cost_rules"

    id: Mapped[int] = mapped_column(primary_key=True)
    tenant_id: Mapped[str] = mapped_column(String(64), default="default")
    process_name: Mapped[str] = mapped_column(String(64), unique=True)
    grading_cost: Mapped[float] = mapped_column(Float, default=0.0)
    bagging_cost: Mapped[float] = mapped_column(Float, default=0.0)
    cracking_cost: Mapped[float] = mapped_column(Float, default=0.0)
    created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)


class PackagingCostRule(Base):
    __tablename__ = "packaging_cost_rules"

    id: Mapped[int] = mapped_column(primary_key=True)
    tenant_id: Mapped[str] = mapped_column(String(64), default="default")
    sale_type: Mapped[str] = mapped_column(String(64))
    unit_of_measure: Mapped[str] = mapped_column(String(64))
    own_bag: Mapped[bool] = mapped_column(Boolean, default=False)
    bag_cost: Mapped[float] = mapped_column(Float, default=0.0)
    created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)


class FreightCostRule(Base):
    __tablename__ = "freight_cost_rules"

    id: Mapped[int] = mapped_column(primary_key=True)
    tenant_id: Mapped[str] = mapped_column(String(64), default="default")
    sale_type: Mapped[str] = mapped_column(String(64))
    unit_of_measure: Mapped[str] = mapped_column(String(64))
    cost_per_unit: Mapped[float] = mapped_column(Float, default=0.0)
    created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
