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

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 入群申请
 * 2022-11-26 10:55:18
 */
@ApiModel(value = "ImGroupMemberAuditWrapper对象", description = "入群申请查询对象")
public class ImGroupMemberAuditWrapper {

    @Data
	@Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" ImGroupMemberAuditQuery-入群申请")
    public static class ImGroupMemberAuditQuery implements QueryInfo {
    
    	@ApiModelProperty("当前页")
        private Integer page;
        
        @ApiModelProperty("分页行数")
        private Integer rows;
        
        @ApiModelProperty("关键字匹配")
		private String keyword;

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

    @Data
	@Builder
    @NoArgsConstructor
    @AllArgsConstructor
	@ApiModel(" ImGroupMemberAudit-入群申请")
    public static class ImGroupMemberAudit {

		@ApiModelProperty("主键")
		private Long id;
                        
		@ApiModelProperty("用户ID") 
		private Long userId;
                        
		@ApiModelProperty("用户身份") 
		private String clientType;
                        
		@ApiModelProperty("群角色TEACHER老师、STUDENT学生") 
		private String roleType;
                        
		@ApiModelProperty("群组编号") 
		private String groupId;
                        
		@ApiModelProperty("申请原因") 
		private String desc;
                        
		@ApiModelProperty("审核状态AUDITING,REJECT,OPEN") 
		private String auditStatus;
                        
		@ApiModelProperty("修改时间") 
		private Date updateTime;
                        
		@ApiModelProperty("创建时间") 
		private Date createTime;

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

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

    /**
     * 批量审核入群申请
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ApplyBatchAudit implements Serializable {

        @ApiModelProperty("审核编号列表")
        private String auditIds;

        @ApiModelProperty("群组ID")
        private String groupId;

        @ApiModelProperty("审核状态")
        private String auditStatus;

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

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

        public List<Long> getBatchAuditIds() {

            if (StringUtils.isNotEmpty(getAuditIds())) {
                return Arrays.stream(getAuditIds().split(",")).map(Long::new).collect(Collectors.toList());
            }
            return Lists.newArrayList();
        }
    }
}