package com.yonge.cooleshow.teacher.controller;


import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.entity.ImGroupMember;
import com.yonge.cooleshow.biz.dal.entity.ImGroupMemberAudit;
import com.yonge.cooleshow.biz.dal.enums.AuditStatusEnum;
import com.yonge.cooleshow.biz.dal.queryInfo.ImGroupMemberAuditQueryInfo;
import com.yonge.cooleshow.biz.dal.service.ImGroupMemberAuditService;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.cooleshow.common.exception.BizException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * (ImGroupMemberAudit)表控制层
 *
 * @author zx
 * @since 2022-03-22 17:18:51
 */
@Api(tags = "入群申请")
@RestController
@RequestMapping("/imGroupMemberAudit")
public class ImGroupMemberAuditController extends BaseController {

    @Resource
    private ImGroupMemberAuditService imGroupMemberAuditService;
    @Resource
    private SysUserFeignService sysUserFeignService;

    @ApiOperation("申请入群")
    @PostMapping(value = "/apply")
    public HttpResponseResult apply(@Valid @RequestBody ImGroupMemberAudit imGroupMemberAudit) throws Exception {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        imGroupMemberAudit.setRoleType(ImGroupMember.ImGroupMemberRoleType.TEACHER);
        imGroupMemberAudit.setUserId(sysUser.getId());
        imGroupMemberAuditService.apply(imGroupMemberAudit);
        return succeed();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "auditIds", dataType = "String", value = "审核编号列表",required = true),
            @ApiImplicitParam(name = "auditStatus", dataType = "String", value = "审核状态",required = true),
            @ApiImplicitParam(name = "groupId", dataType = "String", value = "审核状态",required = true)
    })
    @ApiOperation("申请入群批量审核")
    @PostMapping(value = "/applyAudit")
    public HttpResponseResult applyAudit(@RequestBody Map<String,String> params) throws Exception {
        if(Objects.isNull(params.get("auditIds"))
                || Objects.isNull(params.get("auditStatus"))
                || Objects.isNull(params.get("groupId"))){
            throw new BizException("参数校验失败");
        }
        imGroupMemberAuditService.applyAudit(params.get("auditIds"),
                AuditStatusEnum.valueOf(params.get("auditStatus")),
                params.get("groupId"));
        return succeed();
    }

    @ApiOperation("申请入群列表")
    @PostMapping(value = "/queryAll")
    public HttpResponseResult<List<ImGroupMemberAudit>> queryAll(@Valid @RequestBody ImGroupMemberAuditQueryInfo queryInfo){
        return succeed(imGroupMemberAuditService.queryAll(queryInfo));
    }

}

