package com.pjilisense.flxai.controller;

import com.pjilisense.flxai.base.constant.Constant;
import com.pjilisense.flxai.dto.AppAiPluginDTO;
import com.pjilisense.flxai.page.PageData;
import com.pjilisense.flxai.utils.Result;
import com.pjilisense.flxai.dto.AppAiModelDTO;
import com.pjilisense.flxai.service.AppAiModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * AI模型表
 *
 * @author liushujing liushujing@philisense.com
 * @since 1.0.0 2024-12-20
 */
@RestController
@RequestMapping(Constant.BASE_PATH+"appaimodel")
@Api(tags="AI模型表")
public class AppAiModelController {

    private static Logger logger = LoggerFactory.getLogger(AppAiModelController.class);

    @Autowired
    private AppAiModelService appAiModelService;

    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="Integer", dataTypeClass =Integer.class) ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="Integer", dataTypeClass =Integer.class) ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String", dataTypeClass =String.class) ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String", dataTypeClass =String.class)
    })
    public Result<PageData<AppAiModelDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<AppAiModelDTO> page = appAiModelService.page(params);

        return new Result<PageData<AppAiModelDTO>>().ok(page);
    }
    @GetMapping("getAllAiModel")
    @ApiOperation("获取所有收藏")
    public Result<List<Map<String, Object>>> getAllAiModel(@RequestParam("userid") String userid){
        List<Map<String, Object>> allTools = appAiModelService.getAllAiModel(userid);
        return new Result<List<Map<String, Object>>>().ok(allTools);
    }
    @GetMapping("{id}")
    @ApiOperation("信息")
    public Result<AppAiModelDTO> get(@PathVariable("id") Long id){
        AppAiModelDTO data = appAiModelService.get(id);

        return new Result<AppAiModelDTO>().ok(data);
    }

    @PostMapping
    @ApiOperation("保存")
    public Result save(@RequestBody AppAiModelDTO dto){
        //效验数据

        appAiModelService.save(dto);

        return new Result<AppAiModelDTO>().ok(dto);
    }

    @PutMapping
    @ApiOperation("修改")
    public Result update(@RequestBody AppAiModelDTO dto){
        //效验数据

        appAiModelService.update(dto);

        return new Result();
    }

    @DeleteMapping
    @ApiOperation("删除")
    public Result delete(@RequestBody String[] ids){
        //效验数据
        appAiModelService.delete(ids);

        return new Result();
    }

    @GetMapping("deleteByIdentifier")
    @ApiOperation("删除")
    public Result deleteByIdentifier(@RequestParam("userid") String userid, @RequestParam("identifier") String identifier){
        //效验数据
        appAiModelService.deleteByIdentifier(userid,identifier);

        return new Result();
    }

}