package com.qmth.exam.reserve.controller.admin;

import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.boot.core.collection.PageResult;
import com.qmth.exam.reserve.bean.asynctask.AsyncTaskReq;
import com.qmth.exam.reserve.bean.asynctask.AsyncTaskTypeVO;
import com.qmth.exam.reserve.bean.asynctask.AsyncTaskVO;
import com.qmth.exam.reserve.bean.login.LoginUser;
import com.qmth.exam.reserve.controller.BaseController;
import com.qmth.exam.reserve.enums.AsyncTaskType;
import com.qmth.exam.reserve.service.AsyncTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "【管理端】异步任务相关接口")
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin/async/task")
@Aac(strict = false, auth = true)
public class AsyncTaskController extends BaseController {

    @Autowired
    private AsyncTaskService asyncTaskService;

    @ApiOperation(value = "异步任务业务类型")
    @PostMapping(value = "/type/list")
    public List<AsyncTaskTypeVO> list() {
        AsyncTaskType[] values = AsyncTaskType.values();
        List<AsyncTaskTypeVO> list = new ArrayList<>(values.length);
        for (AsyncTaskType value : values) {
            AsyncTaskTypeVO vo = new AsyncTaskTypeVO();
            vo.setType(value.name());
            vo.setName(value.getTitle());
            list.add(vo);
        }
        return list;
    }

    @ApiOperation(value = "异步任务管理分页")
    @PostMapping(value = "/page")
    public PageResult<AsyncTaskVO> page(@RequestBody AsyncTaskReq req) {
        LoginUser loginUser = this.curLoginUser();
        req.setOperateId(loginUser.getId());
        return asyncTaskService.pageAsyncTask(req);
    }



}
