package com.gree.mall.miniapp.controller.worker;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.miniapp.bean.worker.TeamCount;
import com.gree.mall.miniapp.bean.worker.WebsitWorkerBean;
import com.gree.mall.miniapp.enums.ExamineStatusEnum;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.worker.WorkerTeamLogic;
import com.gree.mall.miniapp.plus.entity.WorkerTeam;
import com.gree.mall.miniapp.plus.entity.WorkerTeamApply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
@RestController
@Api(value = "师傅组别", tags = {"师傅组别"})
@RequestMapping(value = "/worker/team", produces = "application/json; charset=utf-8")
public class WorkerTeamController {

    @Resource
    WorkerTeamLogic workerTeamLogic;


    @PostMapping("/page")
    @ApiOperation(value = "列表")
    public ResponseHelper<Page<WorkerTeamApply>> page(
            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize

    ) throws RemoteServiceException {
        IPage<WorkerTeamApply> page = workerTeamLogic.page(pageNum, pageSize);
        return ResponseHelper.success(page);
    }

    @PostMapping("/manage/page")
    @ApiOperation(value = "后台列表")
    public ResponseHelper<Page<WorkerTeam>> managePage(
            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize
    ) throws RemoteServiceException {
        IPage<WorkerTeam> page = workerTeamLogic.managePage(pageNum, pageSize);
        return ResponseHelper.success(page);
    }

    @PostMapping("/add")
    @ApiOperation("新增")
    public ResponseHelper add(@RequestBody WorkerTeamApply workerTeam) throws RemoteServiceException {
        workerTeamLogic.add(workerTeam);
        return ResponseHelper.success();
    }

    @PostMapping("/confirm")
    @ApiOperation("确认")
    public ResponseHelper confirm(
            @ApiParam(value = "申请id", required = true) @RequestParam String id,
            @ApiParam(value = "确认状态 OK=同意 FAIL=不同意", required = true) @RequestParam ExamineStatusEnum status) throws RemoteServiceException {
        workerTeamLogic.confirm(id, status);
        return ResponseHelper.success();
    }

    @PostMapping("/query/websit/worker")
    @ApiOperation("查询网点入驻的师傅")
    public ResponseHelper<List<WebsitWorkerBean>> queryWebsitWorker (
            @ApiParam(value = "网点编号", required = true) @RequestParam String websitId
    ) {
        List<WebsitWorkerBean> list = workerTeamLogic.queryWebsitWorker(websitId);
        return ResponseHelper.success(list);
    }

    @PostMapping("/count")
    @ApiOperation(value = "统计")
    public ResponseHelper<TeamCount> count(

    ) throws RemoteServiceException {
        TeamCount count = workerTeamLogic.count();
        return ResponseHelper.success(count);
    }
}
