package tech.easyflow.admin.controller.ai;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import tech.easyflow.ai.entity.PluginCategory;
import tech.easyflow.ai.entity.PluginCategoryMapping;
import tech.easyflow.ai.service.PluginCategoryMappingService;
import tech.easyflow.common.annotation.UsePermission;
import tech.easyflow.common.domain.Result;
import tech.easyflow.common.web.controller.BaseCurdController;
import tech.easyflow.common.web.jsonbody.JsonBody;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

/**
 *  控制层。
 *
 * @author wangGangQiang
 * @since 2025-05-21
 */
@RestController
@RequestMapping("/api/v1/pluginCategoryMapping")
@UsePermission(moduleName = "/api/v1/plugin")
public class PluginCategoryMappingController extends BaseCurdController<PluginCategoryMappingService, PluginCategoryMapping> {
    public PluginCategoryMappingController(PluginCategoryMappingService service) {
        super(service);
    }

    @Resource
    private PluginCategoryMappingService relationService;

    @PostMapping("/updateRelation")
    @SaCheckPermission("/api/v1/plugin/save")
    public Result<Boolean> updateRelation(
            @JsonBody(value="pluginId") BigInteger pluginId,
            @JsonBody(value="categoryIds") ArrayList<BigInteger> categoryIds
    ){
        return Result.ok(relationService.updateRelation(pluginId, categoryIds));
    }

    @GetMapping("/getPluginCategories")
    public Result<List<PluginCategory>> getPluginCategories(@RequestParam(value="pluginId") BigInteger pluginId
    ){
        return Result.ok(relationService.getPluginCategories(pluginId));
    }
}
