package com.fzm.mall.server.front.goods.model;

import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;

import com.fzm.mall.server.front.constant.MALLGlobalConfig;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 商品表
 * </p>
 *
 * @author fzm
 * @since 2021-03-02
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("goods_spu")
@ApiModel(value="Spu对象", description="商品表")
public class GoodSpu implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final Integer SPU_TYPE_NFT = 6;

    /**
     * 1.是，自动生成Token 2.是，使用外部既有Token
     */
    public static final Integer COMMODITY_PASS_AUTO = 1;

    public static final Integer COMMODITY_PASS_OUT = 2;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "商品编号")
    private String goodsId;

    @ApiModelProperty(value = "商户编号")
    private String merchantId;

    @ApiModelProperty(value = "商品类目")
    private String categoryId;

    @ApiModelProperty(value = "物流模板id")
    private String templateId;

    @ApiModelProperty(value = "类型  1:普通   2:预售   3:竞拍   4:秒杀")
    private Integer type;

    @ApiModelProperty(value = "商品名称")
    private String name;

    @ApiModelProperty(value = "描述")
    private String description;

    @ApiModelProperty(value = "商品属性")
    private String prop;

    @ApiModelProperty(value = "详情")
    private String detail;

    @ApiModelProperty(value = "缩略图")
    private String thumb;

    @ApiModelProperty(value = "视频")
    private String video;

    @ApiModelProperty(value = "商品最贵spu价格")
    private BigDecimal maxPrice;

    @ApiModelProperty(value = "默认价格（第一个规格的价格）")
    private BigDecimal defaultPrice;

    @ApiModelProperty(value = "视频封面")
    private String videoPoster;

    @ApiModelProperty(value = "商品图片列表")
    private String imgList;

    @ApiModelProperty(value = "状态 0: 删除  1: 上架  2: 下架  3: 发行中  4: 失败   5:待审核   6:审核未通过")
    private Integer status;

    @ApiModelProperty(value = "积分数量")
    private Integer bpNum;

    @ApiModelProperty(value = "1-7天无理由退换货 2-自定义")
    private Integer returnType;

    @ApiModelProperty(value = "退货描述")
    private String returnDesc;

    @ApiModelProperty(value = "商品备注")
    private String note;

    @ApiModelProperty(value = "审核失败原因")
    private String checkFailReason;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private Long createTime;

    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateTime;

    @ApiModelProperty(value = "1.是，自动生成Token 2.是，使用外部既有Token")
    @TableField(exist = false)
    private Integer commodityPass;

    @ApiModelProperty(value = "tokenId")
    @TableField(exist = false)
    private Long tokenId;

    @ApiModelProperty(value = "tokenId")
    @TableField(exist = false)
    private String tokenIdStr;

    @ApiModelProperty(value = "1.外部nft;2.内部nft；3.内部普通")
    @TableField(exist = false)
    private Integer coinType;

    public void initTokenId() {
        if (commodityPass.equals(COMMODITY_PASS_OUT)){
            setTokenId(Long.valueOf(tokenIdStr));
        }else if(commodityPass.equals(COMMODITY_PASS_AUTO) && type == 6){
            setTokenId(Long.valueOf(getTokenIdStr().replace( MALLGlobalConfig.GOODS_NFT_PREFIX,"")));
        }
    }

    private String nftFile;
}
