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

import com.alibaba.fastjson.JSON;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import com.yonge.cooleshow.biz.dal.enums.GenderEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDate;
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 javax.validation.constraints.NotNull;

/**
 * 机构小组表
 * 2023-10-11 09:24:50
 */
@ApiModel(value = "TenantGroupWrapper对象", description = "机构小组表查询对象")
public class TenantGroupWrapper {

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" TenantGroupQuery-机构小组表")
    public static class TenantGroupQuery implements QueryInfo {

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

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

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

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

        @ApiModelProperty("机构小组负责人")
        private Long adminId;

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

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

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

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

    @Data
    @ApiModel(" TenantGroup-机构小组表")
    public static class TenantGroup {

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

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

        @ApiModelProperty("小组名称")
        private String name;

        @ApiModelProperty("管理员ID")
        private Long adminId;

        @ApiModelProperty("管理员名称")
        private String adminName;

        @ApiModelProperty("IM群聊ID")
        private String imGroupId;

        @ApiModelProperty("IM群聊是否存在")
        private Boolean imGroupExist;

        @ApiModelProperty("创建人")
        private Long createBy;

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

        @ApiModelProperty("群成员列表")
        private List<Long> userIds = new ArrayList<>();

        @ApiModelProperty("群成员列表")
        private List<TenantGroupMember> userList = new ArrayList<>();

        @ApiModelProperty("群成员数量")
        private Integer groupUserCount = 0;

        @ApiModelProperty("专辑数量")
        private Integer albumCount = 0;

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

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

    @Data
    @ApiModel(" TenantGroup-机构小组成员")
    public static class TenantGroupMember {

        @ApiModelProperty("userId")
        private Long userId;

        @ApiModelProperty("所属机构，开放接口必填")
        private Long tenantId;

        @ApiModelProperty("姓名")
        private String name;

        @ApiModelProperty("性别。0：女 1：男")
        private GenderEnum gender;

        @ApiModelProperty("生日")
        private Date birthdate;

        @ApiModelProperty("手机号码")
        private String phone;

        @ApiModelProperty("头像")
        private String avatar;

        @ApiModelProperty("声部")
        private String subjectId;

        @ApiModelProperty("声部")
        private String subjectName;

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

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

    @Data
    @ApiModel("调整机构小组")
    public static class AdjustTenantGroup {

        @ApiModelProperty("移交前的负责人ID")
        @NotNull
        private Long teacherId;

        @ApiModelProperty("机构小组调整详情")
        private List<AdjustTenantGroupDetail> adjustTenantGroupDetails = new ArrayList<>();

    }

    @Data
    @ApiModel("调整机构小组详情")
    public static class AdjustTenantGroupDetail{
        @ApiModelProperty("机构小组ID")
        private Long tenantGroupId;

        @ApiModelProperty("移交后的负责人ID")
        private Long teacherId;

        @ApiModelProperty("是否解散")
        private Boolean dismiss = false;
    }

}