package com.hys.app.model.erp.dos;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.hys.app.framework.database.mybatisplus.base.BaseDO;
import com.hys.app.model.erp.dto.ProductSpec;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


/**
 * 产品实体类
 *
 * @author 张崧
 * 2023-11-30 16:06:44
 */
@TableName(value = "erp_product", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@NoArgsConstructor
public class ProductDO extends BaseDO {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(hidden = true)
    private Long id;

    /**
     * 关联 {@link GoodsDO#getId()}
     */
    @ApiModelProperty(name = "goods_id", value = "商品id")
    private Long goodsId;

    // ============= product自己的字段 =============

    @ApiModelProperty(name = "hire_or_sail", value = "租赁sku还是售卖sku")
    private String hireOrSail;

    @ApiModelProperty(name = "price", value = "销售价格")
    private Double price;

    @ApiModelProperty(name = "cost_price", value = "成本价格")
    private Double costPrice;

    @ApiModelProperty(name = "retail_price", value = "零售价格")
    private Double retailPrice;

    @ApiModelProperty(name = "mkt_price", value = "市场价格")
    private Double mktPrice;

    @ApiModelProperty(name = "weight", value = "重量")
    private Double weight;

    @ApiModelProperty(name = "unit", value = "单位")
    private String unit;

    @ApiModelProperty(name = "spec_list", value = "规格列表")
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private SpecList specList;

    @ApiModelProperty(name = "image", value = "产品图片")
    private String image;

    @ApiModelProperty(name = "day_price", value = "日租金")
    private BigDecimal dayPrice;

    @ApiModelProperty(name = "barCode", value = "条码")
    private String barCode;

    @ApiModelProperty(name = "sku", value = "sku")
    private String sku;

    @ApiModelProperty(name = "是否有序列号", value = "商品视频")
    private Boolean haveSn;

    @ApiModelProperty(name = "sort", value = "排序")
    private Long sort;

    /**
     * 解决JacksonTypeHandler反序列化问题
     */
    public static class SpecList extends ArrayList<ProductSpec> {
    }
}
