package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.request.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.EmployeeTrainingService;
import com.cool.store.vo.AssessmentUserTrainingVO;
import com.cool.store.vo.EmployeeTrainingDetailVO;
import com.cool.store.vo.EmployeeTrainingVO;
import com.cool.store.vo.EmployeeUserTrainingVO;
import com.github.pagehelper.PageInfo;
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.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author byd
 * @date 2024-04-30 10:15
 */
@Api(tags = "PC员工培训")
@RestController
@RequestMapping("pc/employeeTraining")
public class EmployeeTrainingController {

    @Resource
    private EmployeeTrainingService employeeTrainingService;


    @ApiOperation("培训员工列表")
    @GetMapping("/trainingListByShopId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopId", value = "店铺id", required = true)
    })
    public ResponseResult<List<EmployeeTrainingVO>> trainingListByShopId(@RequestParam("shopId") Long shopId) {
        return ResponseResult.success(employeeTrainingService.trainingListByShopId(shopId));
    }

    @ApiOperation("待训员工列表")
    @PostMapping("/employeeTrainingList")
    public ResponseResult<PageInfo<EmployeeTrainingVO>> employeeTrainingList(@RequestBody EmployeeTrainingRequest employeeTrainingRequest) {
        return ResponseResult.success(employeeTrainingService.employeeTrainingList(CurrentUserHolder.getUserId(), employeeTrainingRequest));
    }

    @ApiOperation("员工培训详情")
    @GetMapping("/employeeTrainingDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true)
    })
    public ResponseResult<EmployeeTrainingDetailVO> employeeTrainingDetail(@RequestParam("id") Long id) {
        return ResponseResult.success(employeeTrainingService.employeeTrainingDetail(id));
    }

    @ApiOperation("员工培训--分配")
    @PostMapping("/distribution")
    public ResponseResult<Boolean> distribution(@RequestBody EmployeeTrainingDetailRequest request) {
        employeeTrainingService.distribution(request);
        return ResponseResult.success(Boolean.TRUE);
    }

    @ApiOperation("培训进度-列表")
    @PostMapping("/trainingScheduleList")
    public ResponseResult<PageInfo<EmployeeTrainingVO>> trainingScheduleList(@RequestBody EmployeeTrainingRequest employeeTrainingRequest) {
        employeeTrainingRequest.setAssignFlag(Boolean.TRUE);
        return ResponseResult.success(employeeTrainingService.employeeTrainingList(CurrentUserHolder.getUserId(), employeeTrainingRequest));
    }


    @ApiOperation("培训-教练员-员工列表")
    @GetMapping("/trainerUserList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "带训状态 0-未完成  1-已完成"),
            @ApiImplicitParam(name = "pageNum", value = "分页页数"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小"),
    })
    public ResponseResult<PageInfo<EmployeeTrainingVO>> trainerUserList(@RequestParam(value = "status", required = false) Integer status,
                                                                    @RequestParam(value = "pageNum" ,defaultValue = "1")Integer pageNum,
                                                                    @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize) {
        return ResponseResult.success(employeeTrainingService.trainerUserList(CurrentUserHolder.getUserId(), status, pageNum, pageSize));
    }

    @ApiOperation("培训-教练员-员工带训详情")
    @RequestMapping("/trainerUserDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true)
    })
    public ResponseResult<EmployeeUserTrainingVO> trainerUserDetail(Long id) {
        return ResponseResult.success(employeeTrainingService.trainerUserDetail(id));
    }

    @ApiOperation("培训-教练员-提交培训")
    @PostMapping("/trainerUserCommit")
    public ResponseResult<Boolean> trainerUserCommit(@RequestBody EmployeeTrainingCommitListRequest request) {
        employeeTrainingService.trainerUserCommit(request);
        return ResponseResult.success(Boolean.TRUE);
    }


    @ApiOperation("培训-战区经理-考核员工列表")
    @PostMapping("/assessmentUserList")
    public ResponseResult<PageInfo<EmployeeTrainingVO>> assessmentUserList(@RequestBody EmployeeAssessmentRequest request) {
        return ResponseResult.success(employeeTrainingService.assessmentUserList(CurrentUserHolder.getUserId(), request));
    }

    @ApiOperation("培训-督导-考核员工列表")
    @PostMapping("/supervisorUserList")
    public ResponseResult<PageInfo<EmployeeTrainingVO>> supervisorUserList(@RequestBody EmployeeAssessmentRequest request) {
        return ResponseResult.success(employeeTrainingService.assessmentUserList(CurrentUserHolder.getUserId(), request));
    }

    @ApiOperation("培训-战区经理-员工考核详情")
    @RequestMapping("/assessmentUserDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "员工id", required = true)
    })
    public ResponseResult<AssessmentUserTrainingVO> assessmentUserDetail(Long id) {
        return ResponseResult.success(employeeTrainingService.assessmentUserDetail(id));
    }

    @ApiOperation("培训-实训考核-转交")
    @PostMapping("/turn")
    public ResponseResult<Boolean> turn(@RequestBody EmployeeAssessmentTurnRequest request) {
        employeeTrainingService.turn(request.getId(), CurrentUserHolder.getUserId(), request.getTurnUserId());
        return ResponseResult.success(Boolean.TRUE);
    }

    @ApiOperation("培训-实训考核-提交考核结果")
    @PostMapping("/assessmentUserCommit")
    public ResponseResult<Boolean> assessmentUserCommit(@RequestBody EmployeeAssessmentCommitListRequest request) {
        employeeTrainingService.assessmentUserCommit(request, CurrentUserHolder.getUser());
        return ResponseResult.success(Boolean.TRUE);
    }


}
