package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.service.sysmgr.dto.sysmgr.AccessCreateDto;
import com.crunii.micro.service.sysmgr.dto.sysmgr.AccessPageDto;
import com.crunii.micro.service.sysmgr.dto.sysmgr.AccessPageVo;
import com.crunii.micro.service.sysmgr.dto.sysmgr.AccessUpdateDto;
import com.crunii.micro.service.sysmgr.service.AccessService;
import com.crunii.micro.web.mvc.CurrWorker;
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 springfox.documentation.annotations.ApiIgnore;

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

/**
 * 接入管理
 * @author baoxy
 * @date 2023-07-11
 */
@Api(tags = "接入管理")
@RestController
@RequestMapping("/auth/AccessController")
public class AccessController {

    @Resource
    private AccessService accessService;

    @ApiOperation(value = "分页查询")
    @RequestMapping(path = "pageSearch", method = RequestMethod.POST)
    @ResponseBody
    public Result<PageRsp<AccessPageVo>> pageSearch(@RequestBody PageReq<AccessPageDto> req) {
        return accessService.pageSearch(req);
    }

    @ApiOperation(value = "新增配置")
    @RequestMapping(path = "create", method = RequestMethod.POST)
    @ResponseBody
    public Result<Object> create(@Valid @RequestBody AccessCreateDto dto, @CurrWorker @ApiIgnore Worker worker) {
        return accessService.create(dto, worker);
    }

    @ApiOperation(value = "修改配置")
    @RequestMapping(path = "update", method = RequestMethod.POST)
    @ResponseBody
    public Result<Object> update(@Valid @RequestBody AccessUpdateDto dto, @CurrWorker @ApiIgnore Worker worker) {
        return accessService.update(dto, worker);
    }

    @ApiOperation(value = "变更状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "app的主键id", required = true, dataType = "String")
    })
    @RequestMapping(path = "updateState", method = RequestMethod.GET)
    @ResponseBody
    public Result<Object> updateState(String appId, @CurrWorker @ApiIgnore Worker worker) {
        return accessService.updateState(appId, worker);
    }

    /**
     * 查询系统列表
     * @return
     */
    @RequestMapping(path = "list", method = RequestMethod.GET)
    @ResponseBody
    public Result<List<AccessPageVo>> list(@CurrWorker @ApiIgnore Worker worker) {
        return accessService.list(worker.getLoginId());
    }

    /**
     * 查询系统列表
     * @return
     */
    @RequestMapping(path = "getTrainBusinessType", method = RequestMethod.GET)
    @ResponseBody
    public Result<List<AccessPageVo>> getTrainBusinessType(@CurrWorker @ApiIgnore Worker worker) {
        return accessService.getTrainBusinessType(worker.getLoginId());
    }
}
