package com.yonge.cooleshow.admin.io.request;

import com.alibaba.fastjson.JSON;
import com.yonge.cooleshow.biz.dal.enums.MK;
import com.yonge.toolset.base.page.QueryInfo;
import com.yonge.toolset.base.util.StringUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * 活动老师信息
 * Created by Eric.Shang on 2022/8/29.
 */
public class ActivityTeacherVO {

    /**
     * 活动老师请求信息
     */
    @Data
    @EqualsAndHashCode(callSuper = false)
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(value = "分享活动老师请求", description = "分享活动老师信息")
    public static class RequestInfo extends QueryInfo {

        @ApiModelProperty("活动ID")
        private Long activityId;
        @ApiModelProperty("老师编号/真实姓名/昵称/手机号")
        private String keyword;
        @ApiModelProperty("声部id（多个逗号隔开）")
        private String subjectIds;
        @ApiModelProperty("新增老师搜索, 1: 新增搜索; 0:已添加老师")
        private Integer addType;

        @ApiModelProperty(hidden = true)
        private List<Long> subjectIdList;
        @ApiModelProperty(hidden = true)
        private Long id;
        @ApiModelProperty(hidden = true)
        private String mobile;
        @ApiModelProperty(hidden = true)
        private String name;

        public String jsonString() {

            return JSON.toJSONString(this);
        }

        public Integer getAddType() {
            return Optional.ofNullable(addType).orElse(0);
        }

        public List<Long> getSubjectIdList() {

            if (StringUtils.isNotEmpty(getSubjectIds())) {
                this.subjectIdList = StringUtil.toLongList(subjectIds);
            }

            return subjectIdList;
        }

        public Long getId() {

            if (StringUtils.isNotEmpty(getKeyword())
                    && !getKeyword().matches(MK.EXP_MOBILE_NUMBER)
                    && getKeyword().matches(MK.EXP_INT)) {

                return Long.parseLong(getKeyword());
            }
            return id;
        }

        public String getMobile() {
            if (StringUtils.isNotEmpty(getKeyword())
                    && getKeyword().matches(MK.EXP_MOBILE_NUMBER)) {
                return getKeyword();
            }
            return mobile;
        }

        public String getName() {

            if (StringUtils.isNotEmpty(getKeyword())
                    && !getKeyword().matches(MK.EXP_MOBILE_NUMBER)
                    && !getKeyword().matches(MK.EXP_INT)) {

                return getKeyword();
            }

            return name;
        }

        public Long getActivityId() {

            if (Optional.ofNullable(this.activityId).orElse(0L) > 0) {
                return this.activityId;
            }
            return null;
        }
    }

    /**
     * 活动老师响应信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(value = "分享活动老师响应", description = "分享活动老师信息")
    public static class ResponseInfo implements Serializable {

        @ApiModelProperty(value = "数据编号")
        private Long id;
        @ApiModelProperty("昵称")
        private String username;
        @ApiModelProperty("真实姓名")
        private String realName;
        @ApiModelProperty("手机号")
        private String phone;
        @ApiModelProperty("声部ID")
        private String subjectId;
        @ApiModelProperty("声部")
        private String subjectName;
        @ApiModelProperty(value = "老师编号")
        private Long teacherId;
    }
}
