package com.miaxis.pc.controller.coach;

import com.miaxis.coach.domain.CoachInfo;
import com.miaxis.coach.dto.CoachInfoPcDTO;
import com.miaxis.coach.service.ICoachInfoService;
import com.miaxis.coach.vo.CoachInfoPcVO;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【教练】Controller
 *
 * @author wwl
 * @date 2021-01-15
 */
@RestController
@RequestMapping("/coach/info")
@Api(tags={"【pc-教练】"})
public class PcCoachInfoController extends BaseController{

    @Autowired
    private ICoachInfoService coachInfoService;

    /**
     * pc查询教练列表
     */
    @PreAuthorize("@ss.hasPermi('coach:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询教练列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<CoachInfoPcVO> list(@ModelAttribute CoachInfoPcDTO coachInfo){
        startPage();
        List<CoachInfoPcVO> list = coachInfoService.queryList(coachInfo);
        return toResponsePageInfo(list);
    }

    /**
     * 获取教练详细信息
     */
    @PreAuthorize("@ss.hasPermi('coach:info:query')")
    @GetMapping(value = "/{coachnum}")
    @ApiOperation("获取教练详细信息")
    public Response<CoachInfo> getInfo(
            @ApiParam(name = "coachnum", value = "教练参数", required = true)
            @PathVariable("coachnum") String coachnum
    ){
        return Response.success(coachInfoService.getById(coachnum));
    }

    /**
     * 新增教练
     */
    @PreAuthorize("@ss.hasPermi('coach:info:add')")
    @Log(title = "教练", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增教练")
    public Response<Integer> add(@RequestBody CoachInfo coachInfo){
        return toResponse(coachInfoService.save(coachInfo) ? 1 : 0);
    }

    /**
     * 修改教练
     */
    @PreAuthorize("@ss.hasPermi('coach:info:edit')")
    @Log(title = "教练", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改教练")
    public Response<Integer> edit(@RequestBody CoachInfo coachInfo){
        return toResponse(coachInfoService.updateById(coachInfo) ? 1 : 0);
    }

    /**
     * 删除教练
     */
    @PreAuthorize("@ss.hasPermi('coach:info:remove')")
    @Log(title = "教练", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{coachnums}")
    @ApiOperation("删除教练")
    public  Response<Integer> remove(
            @ApiParam(name = "coachnums", value = "教练ids参数", required = true)
            @PathVariable String[] coachnums
    ){
        return toResponse(coachInfoService.removeByIds(Arrays.asList(coachnums)) ? 1 : 0);
    }


    /**
     * pc教练密码重置
     */
    @PreAuthorize("@ss.hasPermi('coach:info:resetPassword')")
    @Log(title = "教练", businessType = BusinessTypeEnum.UPDATE)
    @PostMapping("/resetPassword/{coachnums}")
    @ApiOperation("pc教练密码重置")
    public  Response<Integer> resetPassword(
            @ApiParam(name = "coachnums", value = "教练员全国统一编号集合", required = true)
            @PathVariable String[] coachnums
    ){
        return toResponse(coachInfoService.resetPassword(coachnums) ? 1 : 0);
    }



}
