package ink.wgink.service.department.controller.app.api;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.department.DepartmentContainUserDTO;
import ink.wgink.pojo.dtos.department.DepartmentUserDTO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.service.department.service.IDepartmentUserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: DepartmentUserController
 * @Description: 组织部门用户
 * @Author: wanggeng
 * @Date: 2021/1/28 4:19 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "组织部门用户")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/department/user")
public class DepartmentUserAppController extends DefaultBaseController {

    @Autowired
    private IDepartmentUserService departmentUserService;

    @ApiOperation(value = "组织部门用户列表", notes = "组织部门用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-with-user")
    public List<DepartmentUserDTO> listWithUser(@RequestHeader("token") String token) {
        Map<String, Object> params = requestParams();
        return departmentUserService.listWithUser(params);
    }

    @ApiOperation(value = "组织部门用户列表", notes = "组织部门用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/{departmentId}")
    public SuccessResultList<List<DepartmentUserDTO>> listPage(@RequestHeader("token") String token,
                                                               @PathVariable("departmentId") String departmentId, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return departmentUserService.listPage(departmentId, page);
    }

    @ApiOperation(value = "组织部门用户列表", notes = "组织部门用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list/{departmentId}")
    public List<DepartmentUserDTO> list(@RequestHeader("token") String token,
                                        @PathVariable("departmentId") String departmentId) {
        Map<String, Object> params = requestParams();
        return departmentUserService.list(departmentId, params);
    }

    @ApiOperation(value = "组织部门用户ID列表", notes = "组织部门用户ID列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listuserid/{departmentId}")
    public List<String> listUserId(@RequestHeader("token") String token,
                                   @PathVariable("departmentId") String departmentId) {
        return departmentUserService.listUserId(departmentId);
    }

    @ApiOperation(value = "获取组织详情（包含本级用户列表与下级部门列表）", notes = "获取组织详情（包含本级用户列表与下级部门列表）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get-department-contain-user-and-sub/department-id/{departmentId}")
    public DepartmentContainUserDTO getDepartmentContainUserAndSubByDepartmentId(@RequestHeader("token") String token,
                                                                                 @PathVariable("departmentId") String departmentId) {
        return departmentUserService.getDepartmentContainUserAndSubByDepartmentId(departmentId);
    }

}
