package com.yonge.cooleshow.biz.dal.wrapper;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import com.yonge.cooleshow.biz.dal.enums.SubjectTypeEnum;
import com.yonge.cooleshow.common.enums.YesOrNoEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;

/**
 * 机构专辑
 * 2023-07-21 17:32:49
 */
@ApiModel(value = "TenantAlbumWrapper对象", description = "机构专辑查询对象")
public class TenantAlbumWrapper {

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" TenantAlbumQuery-机构专辑")
    public static class TenantAlbumQuery implements QueryInfo {

        @ApiModelProperty("当前页")
        private Integer page;

        @ApiModelProperty("分页行数")
        private Integer rows;

        @ApiModelProperty("关键字匹配")
        private String keyword;

        @ApiModelProperty("机构ID")
        private Long tenantId;

        @ApiModelProperty("状态")
        private Boolean status;

        public String getKeyword() {
            return Optional.ofNullable(keyword).filter(StringUtils::isNotBlank).orElse(null);
        }

        public String jsonString() {
            return JSON.toJSONString(this);
        }

        public static TenantAlbumQuery from(String json) {
            return JSON.parseObject(json, TenantAlbumQuery.class);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" TenantAlbum-机构专辑返回")
    public static class TenantAlbum {

        @ApiModelProperty("主键ID")
        private String id;

        @ApiModelProperty("机构ID")
        private String tenantId;

        @ApiModelProperty("专辑名称")
        private String name;

        @ApiModelProperty("机构名称")
        private String tenantName;

        @ApiModelProperty("机构封面")
        private String tenantImg;

        @ApiModelProperty("专辑介绍")
        private String describe;

        @ApiModelProperty("专辑封面")
        private String coverImg;

        @ApiModelProperty("曲目数")
        private Integer musicNum;

        @ApiModelProperty("平台价格")
        private BigDecimal originalPrice;

        @ApiModelProperty("机构价格")
        private BigDecimal salePrice;

        @ApiModelProperty("原价")
        private BigDecimal costPrice;

        @ApiModelProperty("机构利润")
        private BigDecimal tenantProfits;

        @ApiModelProperty("购买周期")
        private Integer purchaseCycle;

        @ApiModelProperty("曲目声部分类(多个,分隔)")
        private String subjectTypes;

        @ApiModelProperty("启用状态")
        private Boolean status;

        @ApiModelProperty("删除标识")
        private Boolean delFlag;

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

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

        @ApiModelProperty("是否已经购买")
        private Boolean ifBuy;

        @ApiModelProperty("合奏曲目数量")
        private Integer EnsembleCounts;

        @ApiModelProperty("小曲目数量")
        private Integer MusicCounts;

        @ApiModelProperty("声部曲目数")
        private Integer SubjectCounts;

        @ApiModelProperty("专辑分类类型ID")
        private Long categoryTypeId;

        @ApiModelProperty("专辑分类等级ID")
        private Long categoryLevelId;

        @ApiModelProperty("曲目相关信息")
        private List<MusicSheetData> musicSheetData = new ArrayList<>();

        @ApiModelProperty("采购周期类型")
        private String purchaseTypes;

        @ApiModelProperty("专辑采购金额")
        private String purchaseJson;


        @ApiModelProperty("机构专辑有效期开始时间 ")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
        private Date tenantAlbumStartTime;
        /**
         * 有效期结束时间
         */
        @ApiModelProperty("机构专辑有效期结束时间 ")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
        private Date tenantAlbumEndTime;


        @ApiModelProperty(value = "学练工具是否有效 0否 1是")
        private YesOrNoEnum tenantAlbumFlag;

        @ApiModelProperty(value = "0:没有专辑 1：有，但是未解锁，2：有，且已解锁")
        private Integer tenantAlbumStatus;

        public String jsonString() {
            return JSON.toJSONString(this);
        }

        public static TenantAlbum from(String json) {
            return JSON.parseObject(json, TenantAlbum.class);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" TenantAlbum-机构专辑采购")
    public static class TenantAlbumBuy {

        @ApiModelProperty("专辑ID")
        private Long tenantAlbumId;

        @ApiModelProperty("采购数量")
        private Integer buyNumber;

        @ApiModelProperty("采购周期")
        private Integer buyCycle;

        public Boolean isValid() {
            if (this.buyNumber == null || this.buyNumber < 0) {
                return false;
            }
            if (this.buyCycle == null || this.buyCycle < 0 || this.buyCycle % 6 != 0) {
                return false;
            }
            return true;
        }

    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" TenantAlbumContent-机构专辑采购信息")
    public static class TenantAlbumContent {

        @ApiModelProperty("专辑ID")
        private Long tenantAlbumId;

        @ApiModelProperty("采购数量")
        private Integer buyNumber;

        @ApiModelProperty("采购倍数")
        private Integer buyMultiple;

        @ApiModelProperty(value = "采购周期", hidden = true)
        private Integer buyCycle;

        @ApiModelProperty(value = "采购周期类型")
        private String purchaseType;

        @ApiModelProperty(value = "采购机构", hidden = true)
        private Long tenantId;


        @ApiModelProperty("平台价格")
        private BigDecimal originalPrice;

        @ApiModelProperty("机构价格")
        private BigDecimal salePrice;


    }


    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" 机构专辑新增")
    public static class TenantAlbumVo {
        @ApiModelProperty("机构ID")
        private Long tenantId;

        @ApiModelProperty("专辑名称")
        @NotNull
        private String name;

        @ApiModelProperty("机构名称")
        private String tenantName;

        @ApiModelProperty("专辑介绍")
        @NotNull
        private String describe;

        @ApiModelProperty("专辑封面")
        @NotNull
        private String coverImg;

        @ApiModelProperty("曲目声部分类(多个,分隔)")
        private String subjectTypes;

        @ApiModelProperty("曲目相关信息")
        private List<MusicSheetData> musicSheetData = new ArrayList<>();

        @ApiModelProperty("机构价格")
        private BigDecimal salePrice;

        @ApiModelProperty("原价")
        private BigDecimal costPrice;

        @ApiModelProperty("购买周期")
        private Integer purchaseCycle;

    }

    @Data
    public static class MusicSheetData {

        private SubjectTypeEnum subjectType;

        //@ApiModelProperty(value = "声部列表",hidden = true)
        //private List<Long> musicSheetIdList = new ArrayList<>();

        @ApiModelProperty("曲目列表")
        private List<TenantAlbumSheet> tenantAlbumSheetList = new ArrayList<>();

        @ApiModelProperty("类型")
        private String type;

        @ApiModelProperty("级别")
        private String level;

        @ApiModelProperty("标签")
        private String musicTag;
    }



    @Data
    @ApiModel("曲目返回")
    public static class TenantAlbumSheet {

        @ApiModelProperty("主键ID")
        private String id;

        @ApiModelProperty("机构ID")
        private String tenantId;

        @ApiModelProperty("声部分类(ENSEMBLE, MUSIC, SUBJECT)")
        private SubjectTypeEnum subjectType;

        @ApiModelProperty("机构专辑ID")
        private Long tenantAlbumId;

        @ApiModelProperty("曲目ID")
        private Long musicSheetId;

        @ApiModelProperty("曲目排序")
        private Integer sortNumber;

        @ApiModelProperty("删除标识")
        private Boolean delFlag;

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

        @ApiModelProperty("创建时间")
        @TableField(value = "create_time_")
        private Date createTime;

        @ApiModelProperty("级别")
        private String  level;

        @ApiModelProperty("类型")
        private String  type;

        @ApiModelProperty(value = "曲谱名称")
        private String musicSheetName;


        @ApiModelProperty(value = "封面图")
        private String titleImg;


        @ApiModelProperty(value = "艺术家")
        private String composer;

        @ApiModelProperty(value = "曲谱声部(适用的乐器,可能是多个,用逗号分隔)")
        private String musicSubject;

        @ApiModelProperty(value = "曲谱声部名称")
        private String musicSubjectName;

        @ApiModelProperty(value = "曲谱标签(多个标签用逗号分隔)")
        private String musicTag;

        @ApiModelProperty(value = "曲谱标签名称")
        private String musicTagName;

        @ApiModelProperty(value = "曲谱来源(平台用户ID或者是老师ID)")
        private Long userId;

        @ApiModelProperty(value = "上传人")
        private String userName;
    }


    @Data
    public static class TenantAlbumPurchaseJson {

        @ApiModelProperty("采购周期类型")
        private String type;

        @ApiModelProperty("金额")
        private BigDecimal price;
    }

}