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.IAiResourceParseService;
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;

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

    @Autowired
    private IZoneResourceService zoneResourceService;
    @Autowired
    private IAiResourceParseService aiResourceParseService;

    /**
     * 上传ZIP并解析
     */
    @RequiresPermissions("resource:ai: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(aiResourceParseService.parseSkillZip(file));
    }

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

    // ==================== Model 资源接口 ====================

    /**
     * 创建Model资源
     */
    @RequiresPermissions("resource:ai:model:add")
    @Log(title = "创建Model资源", businessType = BusinessType.INSERT)
    @PostMapping("/model")
    @ApiOperation("创建Model资源")
    public AjaxResult addModel(@RequestBody @Validated AiModelInputVo inputVo) {
        return success(zoneResourceService.insertAiModelResource(inputVo));
    }

    /**
     * 修改Model资源
     */
    @RequiresPermissions("resource:ai:model:edit")
    @Log(title = "修改Model资源", businessType = BusinessType.UPDATE)
    @PutMapping("/model")
    @ApiOperation("修改Model资源")
    public AjaxResult editModel(@RequestBody @Validated AiModelUpdateVo updateVo) {
        return success(zoneResourceService.updateAiModelResource(updateVo));
    }

    // ==================== Dataset 资源接口 ====================

    /**
     * 创建Dataset资源
     */
    @RequiresPermissions("resource:ai:dataset:add")
    @Log(title = "创建Dataset资源", businessType = BusinessType.INSERT)
    @PostMapping("/dataset")
    @ApiOperation("创建Dataset资源")
    public AjaxResult addDataset(@RequestBody @Validated AiDatasetInputVo inputVo) {
        return success(zoneResourceService.insertAiDatasetResource(inputVo));
    }

    /**
     * 修改Dataset资源
     */
    @RequiresPermissions("resource:ai:dataset:edit")
    @Log(title = "修改Dataset资源", businessType = BusinessType.UPDATE)
    @PutMapping("/dataset")
    @ApiOperation("修改Dataset资源")
    public AjaxResult editDataset(@RequestBody @Validated AiDatasetUpdateVo updateVo) {
        return success(zoneResourceService.updateAiDatasetResource(updateVo));
    }
}
