package com.microservices.zone.resource.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.zone.resource.domain.ZoneResource;
import com.microservices.zone.resource.domain.vo.*;
import com.microservices.zone.resource.service.IAiSkillParseService;
import com.microservices.zone.resource.service.IZoneResourceService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * AI资源管理Controller
 */
@RestController
@RequestMapping("/ai-resource")
@Api(tags = "AI资源管理接口")
public class AiResourceController extends BaseController {

    @Autowired
    private IZoneResourceService zoneResourceService;
    @Autowired
    private IAiSkillParseService aiSkillParseService;

    /**
     * 上传ZIP并解析
     */
//    @RequiresPermissions("ai:resource:skill:add")
    @PostMapping("/skill/parse")
    @ApiOperation("上传ZIP并解析Skill包")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件实体", paramType = "form", dataType = "_file"),
    })
    public GenericsAjaxResult<AiSkillParseResultVo> parseSkillZip(@RequestPart("file") MultipartFile file) {
        return genericsSuccess(aiSkillParseService.parseSkillZip(file));
    }

    /**
     * 创建Skill资源
     */
//    @RequiresPermissions("ai:resource:skill:add")
    @Log(title = "创建Skill资源", businessType = BusinessType.INSERT)
    @PostMapping("/skill")
    @ApiOperation("创建Skill资源")
    public AjaxResult addSkill(@RequestBody @Validated AiSkillInputVo inputVo) {
        return success(zoneResourceService.insertAiSkillResource(inputVo));
    }

    /**
     * 修改Skill资源
     */
//    @RequiresPermissions("ai:resource:skill:edit")
    @Log(title = "修改Skill资源", businessType = BusinessType.UPDATE)
    @PutMapping("/skill")
    @ApiOperation("修改Skill资源")
    public AjaxResult editSkill(@RequestBody @Validated AiSkillUpdateVo updateVo) {
        return success(zoneResourceService.updateAiSkillResource(updateVo));
    }
}
