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


class ProductionRecord(Base):
    """生产实绩"""
    __tablename__ = "production_records"

    id = Column(Integer, primary_key=True, index=True)
    coil_no = Column(String(30), nullable=False, index=True)
    plan_id = Column(Integer, ForeignKey("production_plans.id"), nullable=True)
    shift = Column(String(10), comment="班次: 甲/乙/丙/丁")
    shift_date = Column(DateTime, comment="班期")
    start_time = Column(DateTime, comment="开始时间")
    end_time = Column(DateTime, comment="结束时间")
    process_length = Column(Float, comment="处理长度m")
    process_weight = Column(Float, comment="处理重量kg")
    avg_speed = Column(Float, comment="平均速度m/min")
    max_speed = Column(Float, comment="最大速度m/min")
    acid_consumption = Column(Float, comment="酸耗量L")
    inlet_thickness = Column(Float, comment="入口厚度mm")
    outlet_thickness = Column(Float, comment="出口厚度mm")
    inlet_width = Column(Float, comment="入口宽度mm")
    quality_grade = Column(String(10), comment="质量等级")
    operator = Column(String(50))
    remark = Column(Text)
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
