package com.hc.web.controller.browser.front;

import com.hc.business.dto.ClassPrintDto;
import com.hc.business.model.UserStatus;
import com.hc.business.service.ClassConfigService;
import com.hc.business.service.UserStatusService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 班次表(ClassConfig)表控制层
 *
 * @author java
 * @since 2020-11-19 16:12:35
 */

@RestController
@RequestMapping("/new/api/front/classConfig")
public class FrontClassConfigController {

    private final UserStatusService userStatusService;
    /**
     * 服务对象
     */
    private final ClassConfigService classConfigService;

    public FrontClassConfigController(UserStatusService userStatusService, ClassConfigService classConfigService) {
        this.userStatusService = userStatusService;
        this.classConfigService = classConfigService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 ClassConfig", response = Result.class)
    public Result selectFrontDetail(@PathVariable("id") Integer id) {
        return Result.success(this.classConfigService.queryById(id));
    }

    @GetMapping("/valid/list")
    @ApiOperation(value = "获取 ClassConfig列表(分页)", response = Result.class)
    public Result listFrontClassConfigByValid(@ApiParam(value = "状态") @RequestParam Integer valid,
                                              @RequestParam(defaultValue = "0") Integer page,
                                              @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(classConfigService.queryByValid(valid, page, size));
    }

    @GetMapping("/list/name")
    @ApiOperation(value = "依据名称 获取 ClassConfig列表", response = Result.class)
    public Result listFrontClassConfigByName(@ApiParam(value = "培训班名称") @RequestParam String name) {
        return Result.success(classConfigService.queryByClassName(name));
    }

    @GetMapping("/area/list")
    @ApiOperation(value = "获取 ClassConfig列表(分页) 地区id", response = Result.class)
    public Result listFrontClassConfigByAreaId(@ApiParam(value = "地区id") @RequestParam Integer areaId,
                                               @RequestParam(defaultValue = "0") Integer page,
                                               @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(classConfigService.queryByAreaId(areaId, page, size));
    }

    @GetMapping("/time/list")
    @ApiOperation(value = "获取 ClassConfig列表(分页) 学习时间", response = Result.class)
    public Result listByStudyStartTime(@ApiParam(value = "开始学习时间") @RequestParam Long studyStartTime,
                                       @RequestParam(defaultValue = "0") Integer page,
                                       @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(classConfigService.queryByTime(studyStartTime, page, size));
    }

    @GetMapping("/list/target")
    @ApiOperation(value = "获取 ClassConfig列表(分页) 学习时间", response = Result.class)
    public Result listByTarget(@ApiParam(value = "培训对象") @RequestParam String target,
                                       @RequestParam(defaultValue = "0") Integer page,
                                       @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(classConfigService.queryByTarget(target, page, size));
    }

    @GetMapping("/list/year")
    @ApiOperation(value = "获取 ClassConfig列表(分页) 学习时间", response = Result.class)
    public Result listByYear(@ApiParam(value = "培训年度") @RequestParam String year,
                               @RequestParam(defaultValue = "0") Integer page,
                               @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(classConfigService.queryByYear(year, page, size));
    }


    @GetMapping("/queryAvailableNumByClassId")
    @ApiOperation(value = "获取已经报名的人数", response = Result.class)
    public Result queryAvailableByClassId(@RequestParam(defaultValue = "0") Integer classId) {
        List<UserStatus> userStatuses = this.userStatusService.queryAvailableByClassId(classId);
        return Result.success(userStatuses.stream().count());
    }

    @GetMapping("/getPrintList")
    @ApiOperation(value = "获取可以打印的证书", response = Result.class)
    public Result getPrintList(String cardId) {
        List<ClassPrintDto> classPrints = this.classConfigService.getPrintList(cardId);
        return Result.success(classPrints);
    }


}