package cd.casic.ci.api;


import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
import cd.casic.ci.process.dto.req.resource.ResourceReq;
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.pojo.PageResult;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ResourceController
 * @Author hopeli
 * @Date 2025/5/10 10:57
 * @Version 1.0
 */

@RestController
@RequestMapping("/resource")
public class ResourceManagerController {

    @Resource
    private ResourceManagerService resourceManagerService;

    @PostMapping(path="/createResource")
    public CommonResult<String> createResource(@RequestBody @Valid ResourceReq resourceReq){

        String resourceId = resourceManagerService.createResource(resourceReq);

        return CommonResult.success(resourceId);
    }


    @PostMapping(path="/deleteResource")
    public CommonResult<Void> deleteResource(@RequestBody @Valid BaseIdReq req){

        resourceManagerService.deleteResource(req.getId());

        return CommonResult.success();
    }

    @PostMapping(path="/findResourceList")
    public CommonResult<List<ResourceFindResp>> findResourceList(@RequestBody @Valid ResourceQueryReq req){

        List<ResourceFindResp> ResourceFindRespList = resourceManagerService.findResourceList(req);

        return CommonResult.success(ResourceFindRespList);
    }



    @PostMapping(path="/updateResource")
    public CommonResult<Void> updateResource(@RequestBody @NotNull @Valid ResourceReq resourceReq){

        resourceManagerService.updateResource(resourceReq);

        return CommonResult.success();
    }


    @PostMapping(path="/findResourcePage")
    public CommonResult<PageResult<ResourceFindResp>> findResourcePage(@RequestBody @NotNull @Valid ResourceQueryReq req){

        PageResult<ResourceFindResp> respPage = resourceManagerService.findResourcePage(req);
        return CommonResult.success(respPage);
    }


    @PostMapping(path="/findResourceById")
    public CommonResult<ResourceFindResp> findResourceById(@RequestBody @Valid BaseIdReq req){

        ResourceFindResp resp = resourceManagerService.findResourceById(req.getId());

        return CommonResult.success(resp);
    }


    @PostMapping(path="/findResourceListByType")
    public CommonResult<TaskResourceFindResp> findResourceListByType(@RequestBody @Valid ResourceQueryReq req){

        TaskResourceFindResp ResourceFindResp = resourceManagerService.findResourceListByType(req);

        return CommonResult.success(ResourceFindResp);
    }



    @PostMapping(path="/findResourceListForObjectByType")
    public CommonResult<List> findResourceListForObjectByType(@RequestBody @Valid ResourceQueryReq req){

        List resp = resourceManagerService.findResourceListForObjectByType(req);

        return CommonResult.success(resp);
    }

}
