package com.ruoyi.school.member.domain;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.core.api.APIBaseResponse;
import com.ruoyi.core.utils.LongArrayTypeHandler;
import com.ruoyi.school.member.domain.req.ReqAddMemberChargeItem;
import com.ruoyi.school.course.domain.resp.course.RespCourseTypeSelect;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 会员卡信息
 * </p>
 *
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "sc_member_card_types",autoResultMap = true)
public class ScMemberCardTypes implements Serializable {




    /**
     * id
     */
    @TableId(value = "card_type_id")
    private Long cardTypeId;

    /**
     * 所属租户
     */
    @TableField("tenant_id")
    private String tenantId;
    /**
     * 会员卡名称
     */
    @TableField("card_name")
    private String cardName;


    /**
     * 课时数量
     */
    @TableField("count")
    private BigDecimal count;

    /**
     * 总价
     */
    @TableField("total_fee")
    private BigDecimal totalFee;

    /**
     * 天数
     */
    @TableField("days")
    private Integer days;


    /**
     * 是否在售 1在售 0停售
     */
    @TableField("sale")
    private String sale;

    /**
     * 删除标志（1删除 0在用）
     */
    @TableField("delete_flag")
    @TableLogic
    private String deleteFlag;

    /**
     * 创建者
     */
    @TableField("create_user")
    private Long createUser;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;

    /**
     * 更新者
     */
    @TableField("last_update_user")
    @JsonIgnore
    private Long lastUpdateUser;

    /**
     * 更新时间
     */
    @TableField("last_update_time")
    @JsonIgnore
    private Date lastUpdateTime;

    //描述
    @TableField("description")
    private String description;
    //条款
    @TableField("terms_and_conditions")
    private String conditions;

    //限制约课次数 1不限次数 2限制约课次数
    private String restrictedNum;
    private String bookTime;//限制约课时间范围 每天 每周 每月
    private Integer bookNum;

    @TableField(value = "course_types", typeHandler = LongArrayTypeHandler.class)
    private Long[] courseTypes;//涵盖课程类型
    @TableField(exist = false)
    private String courseTypesName;//涵盖课程类型

    //付费模式 default  customize自定义
    private String chargeType;

    private BigDecimal defaultNum;
    private BigDecimal defaultFee;

    @TableField(exist = false)
    private List<ReqAddMemberChargeItem> feeModeHourList;//付费模式

    //限制课程 1全部允许 2部分允许
    private String restrictedCourses;
    @TableField(exist = false)
    private List<RespCourseTypeSelect> courseListInType;//课程list
    @TableField(exist = false)
    private List<ScMemberCardCourses> courses;//

    //限制教练 1全部允许 2部分允许
    private String restrictedTeacher;


    @TableField(value = "teacher_list", typeHandler = LongArrayTypeHandler.class)
    private Long[] teacherList;//教练
    @TableField(exist = false)
    private String teachersName;

    @TableField(exist = false)
    private Long courseTypeId;//查询参数 课程类型

    @TableField(exist = false)
    private String cardType;//查询参数 缴费方式

    @TableField(exist = false)
    private Long pageNum;
    @TableField(exist = false)
    private Long pageSize;

    /**
     * 参数校验
     *
     * @return
     */
    public APIBaseResponse checkParam() {
        if (StringUtils.isEmpty(cardName)) {
            return APIBaseResponse.fail("请输入卡类名称");
        }

        if (restrictedNum.equals("2")) {//限制约课次数
            if (StringUtils.isEmpty(bookTime) || ObjectUtil.isEmpty(bookNum)){
                return APIBaseResponse.fail("请核对限制周期和次数");
            }

        }
        if ("customize".equals(chargeType) && (ObjectUtil.isEmpty(feeModeHourList) ||feeModeHourList.size()==0)) {
            return APIBaseResponse.fail("请核对扣费模式");
        }
        if ("default".equals(chargeType) && ObjectUtil.hasEmpty(defaultNum,defaultFee)){
            return APIBaseResponse.fail("请核对扣费模式");
        }

        if ("2".equals(restrictedCourses) ) {
            for (RespCourseTypeSelect l : courseListInType) {
                if (ObjectUtil.isEmpty(l.getSelectedCourses()) ||l.getSelectedCourses().length == 0){
                    return APIBaseResponse.fail("请核对限制课程");
                }
            }

        }

        if ("2".equals(restrictedTeacher) && (ObjectUtil.isEmpty(teacherList) || teacherList.length == 0) ) {
            return APIBaseResponse.fail("请核对限制教练");
        }
        return APIBaseResponse.success();
    }

}

