package com.seer.teach.mall.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.seer.teach.common.entity.BaseEntity;
import com.seer.teach.mall.handler.GoodsSpecAttributesTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 商品对应规格表值表
 * </p>
 *
 * @author Sir-G
 * @since 2025-06-10
 */
@Getter
@Setter
@TableName(value = "mall_goods_specification", autoResultMap = true)
@Schema(name = "GoodsSpecificationEntity对象", description = "商品对应规格表值表" )
public class GoodsSpecificationEntity extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableField("goods_id")
    private Integer goodsId;

    @TableField("pic_url")
    private String picUrl;

    @TableField(exist = false)
    private String spuName;

    /**
     * 商品价格，单位：分
     */
    @TableField("price")
    private BigDecimal price;

    /**
     * 市场价，单位：分
     */
    @TableField("market_price")
    private BigDecimal marketPrice;

    /**
     * 成本价，单位： 分
     */
    @TableField("cost_price")
    private BigDecimal costPrice;

    /**
     * 条形码
     */
    @TableField("bar_code")
    private String barCode;

    /**
     * 库存
     */
    @TableField("stock")
    private Long stock;

    /**
     * 商品重量，单位：kg 千克
     */
    @TableField("weight")
    private String weight;

    /**
     * 商品体积，单位：m^3 平米
     */
    @TableField("volume")
    private String volume;

    /**
     * 商户或个人的userid
     */
    @TableField("merchant_user_id")
    private Long merchantUserId;

    /**
     * 抽成方式：0-无抽成，1-比例抽成，2-金额抽成
     */
    @TableField("commission_type")
    private BigDecimal commissionType;

    /**
     * 比例抽成：抽成百分比，如 5.00 表示 5%
     */
    @TableField("commission_rate")
    private BigDecimal commissionRate;

    /**
     * 金额抽成：固定抽成金额
     */
    @TableField("commission_amount")
    private BigDecimal commissionAmount;

    /**
     * 属性数组，JSON 格式，[{"valueId": 6, "valueName": "二代", "attributeId": 3, "attributeName": "版本"}, {"valueId": 5, "valueName": "Y50", "attributeId": 2, "attributeName": "型号"}]
     */
    @TableField(value = "attributes", typeHandler = GoodsSpecAttributesTypeHandler.class,javaType = true, jdbcType = JdbcType.VARCHAR)
    private List<Attribute> attributes;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "商品属性")
    public static class Attribute {

        @Schema(name = "属性编号", example = "1")
        private Integer attributeId;

        @Schema(name = "属性名字", example = "颜色")
        private String attributeName;

        @Schema(name = "属性值编号", example = "1")
        private Integer valueId;

        @Schema(name = "属性值名字", example = "红色")
        private String valueName;

    }
}