from sqlalchemy import Column, Integer, String, Float, DateTime, Enum, Text, func
from app.database import Base
import enum


class PlanStatus(str, enum.Enum):
    DRAFT = "draft"           # 草稿
    CONFIRMED = "confirmed"   # 已确认
    IN_PROGRESS = "in_progress"  # 执行中
    COMPLETED = "completed"   # 完成
    CANCELLED = "cancelled"   # 取消


class ProductionPlan(Base):
    """生产计划"""
    __tablename__ = "production_plans"

    id = Column(Integer, primary_key=True, index=True)
    plan_no = Column(String(30), unique=True, nullable=False, index=True, comment="计划号")
    plan_date = Column(DateTime, nullable=False, comment="计划日期")
    shift = Column(String(10), comment="班次")
    plan_quantity = Column(Integer, default=0, comment="计划数量（卷）")
    plan_weight = Column(Float, default=0, comment="计划重量kg")
    actual_quantity = Column(Integer, default=0, comment="实际数量（卷）")
    actual_weight = Column(Float, default=0, comment="实际重量kg")
    status = Column(Enum(PlanStatus), default=PlanStatus.DRAFT)
    steel_grade = Column(String(30), comment="主要钢种")
    spec_range = Column(String(50), comment="规格范围")
    priority = Column(Integer, default=5, comment="优先级1-10")
    remark = Column(Text)
    created_by = Column(String(50))
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
