package com.slodon.b2b2c.vo.goods;

import com.slodon.b2b2c.core.constant.GoodsRankConst;
import com.slodon.b2b2c.core.i18n.Language;
import com.slodon.b2b2c.goods.pojo.GoodsRank;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 *
 * 封装榜单列表VO对象
 * @author wuxy
 */
@Data
public class GoodsRankVO {

    @ApiModelProperty("榜单id")
    private Integer rankId;

    @ApiModelProperty("榜单名称")
    private String rankName;

    @ApiModelProperty("榜单分类id")
    private Integer categoryId;

    @ApiModelProperty("榜单分类名称")
    private String categoryName;

    @ApiModelProperty("排序")
    private Integer sort;

    @ApiModelProperty("榜单类型：1-畅销榜；2-好评榜；3-新品榜；4-自定义")
    private Integer rankType;

    @ApiModelProperty("榜单类型：1-畅销榜；2-好评榜；3-新品榜；4-自定义")
    private String rankTypeValue;

    @ApiModelProperty("更新方式：1-自动；0-手动")
    private Integer isAutoUpdate;

    @ApiModelProperty("更新方式：1-自动；0-手动")
    private String isAutoUpdateValue;

    @ApiModelProperty("启用状态：0-未启用；1-启用")
    private Integer state;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("更新时间")
    private Date updateTime;

    public GoodsRankVO(GoodsRank goodsRank) {
        this.rankId = goodsRank.getRankId();
        this.rankName = goodsRank.getRankName();
        this.categoryId = goodsRank.getCategoryId();
        this.categoryName = goodsRank.getCategoryName();
        this.sort = goodsRank.getSort();
        this.rankType = goodsRank.getRankType();
        this.rankTypeValue = dealRankTypeValue(goodsRank.getRankType());
        this.isAutoUpdate = goodsRank.getIsAutoUpdate();
        this.isAutoUpdateValue = dealIsAutoUpdateValue(goodsRank.getIsAutoUpdate());
        this.state = goodsRank.getState();
        this.createTime = goodsRank.getCreateTime();
        this.updateTime = goodsRank.getUpdateTime();
    }

    public static String dealRankTypeValue(Integer rankType) {
        String value = null;
        if (StringUtils.isEmpty(rankType)) return Language.translate("未知");
        switch (rankType) {
            case GoodsRankConst.RANK_TYPE_1:
                value = "畅销榜";
                break;
            case GoodsRankConst.RANK_TYPE_2:
                value = "好评榜";
                break;
            case GoodsRankConst.RANK_TYPE_3:
                value = "新品榜";
                break;
            case GoodsRankConst.RANK_TYPE_4:
                value = "自定义";
                break;
            default:
                break;
        }
        //翻译
        value = Language.translate(value);
        return value;
    }

    public static String dealIsAutoUpdateValue(Integer isAutoUpdate) {
        String value = null;
        if (StringUtils.isEmpty(isAutoUpdate)) return null;
        switch (isAutoUpdate) {
            case GoodsRankConst.IS_AUTO_UPDATE_0:
                value = "手动";
                break;
            case GoodsRankConst.IS_AUTO_UPDATE_1:
                value = "自动";
                break;
            default:
                break;
        }
        //翻译
        value = Language.translate(value);
        return value;
    }
}
