package com.slodon.b2b2c.vo.video;

import com.slodon.b2b2c.core.constant.VideoConst;
import com.slodon.b2b2c.core.i18n.Language;
import com.slodon.b2b2c.core.util.FileUrlUtil;
import com.slodon.b2b2c.video.pojo.Author;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 封装作者个人页VO对象
 *
 * @author wuxy
 */
@Data
public class FrontAuthorVO implements Serializable {

    private static final long serialVersionUID = -4080118726712823859L;
    @ApiModelProperty("作者id")
    private Integer authorId;

    @ApiModelProperty("会员名称")
    private String memberName;

    @ApiModelProperty("会员昵称")
    private String memberNickname;

    @ApiModelProperty("会员头像")
    private String memberAvatar;

    @ApiModelProperty("背景图片")
    private String backgroundImage;

    @ApiModelProperty("简介")
    private String introduction;

    @ApiModelProperty("角色:1会员，2商家")
    private Integer roleType;

    @ApiModelProperty("发布权限状态:0-默认，1-待审核，2-审核通过(正常发布)，3-审核拒绝，4-禁止发布")
    private Integer permissionState;

    @ApiModelProperty("发布权限状态:0-默认，1-待审核，2-审核通过(正常发布)，3-审核拒绝，4-禁止发布")
    private String permissionStateValue;

    @ApiModelProperty("短视频拒绝理由,禁止理由")
    private String remark;

    @ApiModelProperty("直播状态，1-正常；0-禁止")
    private Integer liveState;

    @ApiModelProperty("直播禁止理由")
    private String forbidReason;

    @ApiModelProperty("关注数")
    private String followNum;

    @ApiModelProperty("粉丝数")
    private String fansNum;

    @ApiModelProperty("获赞总数")
    private String likeNum;

    @ApiModelProperty("绑定视频数")
    private Integer videoNum;

    @ApiModelProperty("绑定商品数")
    private Integer goodsNum;

    @ApiModelProperty("点赞视频数")
    private Integer likeVideoNum;

    @ApiModelProperty("直播次数")
    private Integer liveNum;

    @ApiModelProperty("会员等级")
    private Integer grade;

    @ApiModelProperty("店铺id")
    private Long storeId;

    @ApiModelProperty("店铺名称")
    private String storeName;

    @ApiModelProperty("回复和评论消息数")
    private Integer msgNum;

    @ApiModelProperty("是否关注")
    private Boolean isFollow = false;

    @ApiModelProperty("是否自己的主页")
    private Boolean isSelf = false;

    public FrontAuthorVO(Author author) {
        this.authorId = author.getAuthorId();
        this.memberName = author.getMemberName();
        this.memberNickname = author.getMemberNickname();
        this.memberAvatar = author.getMemberAvatar().startsWith("http") ? author.getMemberAvatar() : FileUrlUtil.getFileUrl(author.getMemberAvatar(), null);
        this.backgroundImage = FileUrlUtil.getFileUrl(author.getBackgroundImage(), null);
        this.introduction = author.getIntroduction();
        this.roleType = author.getRoleType();
        this.permissionState = author.getPermissionState();
        this.permissionStateValue = dealPermissionStateValue(author.getPermissionState(), author.getRoleType(), author.getLiveState());
        this.remark = author.getRemark();
        this.liveState = author.getLiveState();
        this.forbidReason = author.getForbidReason();
        this.followNum = author.getFollowNum() < 10000 ? author.getFollowNum().toString()
                : new BigDecimal(author.getFollowNum()).divide(new BigDecimal(10000), 1, RoundingMode.FLOOR) + "w";
        this.fansNum = author.getFansNum() < 10000 ? author.getFansNum().toString()
                : new BigDecimal(author.getFansNum()).divide(new BigDecimal(10000), 1, RoundingMode.FLOOR) + "w";
        //获赞数指短视频点赞数
        this.likeNum = author.getLikeNum() < 10000 ? author.getLikeNum().toString()
                : new BigDecimal(author.getLikeNum()).divide(new BigDecimal(10000), 1, RoundingMode.FLOOR) + "w";
        this.videoNum = author.getVideoNum();
        this.likeVideoNum = author.getLikeVideoNum();
        this.grade = author.getGrade();
        this.storeId = author.getStoreId();
        this.storeName = author.getStoreName();
    }

    public static String dealPermissionStateValue(Integer permissionState, Integer roleType, Integer liveState) {
        String value = "";
        if (StringUtils.isEmpty(permissionState)) {
            return null;
        }
        if (roleType == VideoConst.ROLE_TYPE_1) {
            switch (permissionState) {
                case VideoConst.PERMISSION_STATE_0:
                    value = "申请发布权限";
                    break;
                case VideoConst.PERMISSION_STATE_1:
                    value = "审核中";
                    break;
                case VideoConst.PERMISSION_STATE_2:
                    value = "审核通过";
                    break;
                case VideoConst.PERMISSION_STATE_3:
                    value = "审核失败";
                    break;
                case VideoConst.PERMISSION_STATE_4:
                    value = "禁止发布";
                    break;
                default:
                    break;
            }
        }
        if (roleType == VideoConst.ROLE_TYPE_2 && liveState == VideoConst.LIVE_STATE_0) {
            if (permissionState == VideoConst.PERMISSION_STATE_4) {
                value = "禁止直播、短视频";
            } else {
                value = "禁止直播";
            }
        }
        //翻译
        value = Language.translate(value);
        return value;
    }

}
