package com.bocloud.ims.booter.controller.check;

import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.interfaces.check.ResourceCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/reschecks")
@Api(value = "资源校验", tags = "资源校验")
public class ResourceCheckController {

    @Autowired
    private ResourceCheckService resourceCheckService;

    /**
     * 租户或项目资源校验
     *
     * @param target
     * @param category
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "租户或项目资源校验",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "资源校验", operation = "租户或项目资源校验")
    @GetMapping("/{target}")
    public BocloudResult check(@PathVariable(value = "target") Long target, @RequestParam(value = "category") String category) {
        return resourceCheckService.check(target, category);
    }

    /**
     * 校验租户下用户或项目下用户是否存在未删除的资源
     *
     * @param tenantId
     * @param projectId
     * @param userId
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "校验租户下用户或项目下用户是否存在未删除的资源",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "资源校验", operation = "校验租户下用户或项目下用户是否存在未删除的资源")
    @GetMapping
    public BocloudResult check(@RequestParam(value = Common.TENANTID) Long tenantId, @RequestParam(value = "projectId", required = false) Long projectId, @RequestParam(value = "userId", required = false) Long userId) {
        return resourceCheckService.checkRes(tenantId, projectId, userId);
    }

}
