"""商品销售数据模型 — 波士顿产品矩阵
从《商品销售排行榜》Excel导入，支撑四象限分析
"""
from sqlalchemy import Column, Integer, String, Float, DateTime, func
from app.database import Base


class ProductSales(Base):
    """商品销售月度数据"""
    __tablename__ = "product_sales"

    id = Column(Integer, primary_key=True, index=True)
    entity_id = Column(Integer, default=1, comment="企业ID: 1=酣客 2=博海")
    product_code = Column(String(50), nullable=False, comment="商品编码")
    product_name = Column(String(100), nullable=False, comment="商品名称")
    period_month = Column(String(10), nullable=False, comment="期间 YYYY-MM")
    sales_amount = Column(Float, default=0, comment="销售金额")
    cost_amount = Column(Float, default=0, comment="成本金额")
    gross_profit = Column(Float, default=0, comment="毛利")
    gross_margin_rate = Column(Float, default=0, comment="毛利率(%)")
    sales_qty = Column(Integer, default=0, comment="销售数量")
    unit = Column(String(30), default="", comment="单位")
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
