package com.pjilisense.flxai.controller;

import com.alibaba.fastjson.JSONObject;
import com.pjilisense.flxai.base.constant.Constant;
import com.pjilisense.flxai.page.PageData;
import com.pjilisense.flxai.utils.Result;
import com.pjilisense.flxai.dto.FilesDTO;
import com.pjilisense.flxai.service.FilesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.type.JdbcType;
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;


/**
 * ${comments}
 *
 * @author liushujing liushujing@philisense.com
 * @since 1.0.0 2025-01-14
 */
@RestController
@RequestMapping(Constant.BASE_PATH+"files")
@Api(tags="${comments}")
public class FilesController {

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

    @Autowired
    private FilesService filesService;

    @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<FilesDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<FilesDTO> page = filesService.page(params);
        return new Result<PageData<FilesDTO>>().ok(page);
    }

    @GetMapping("{id}")
    @ApiOperation("信息")
    public Result<FilesDTO> get(@PathVariable("id") String id){
        FilesDTO data = filesService.get(id);

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

    @PostMapping
    @ApiOperation("保存")
    public Result save(@RequestBody FilesDTO dto){
        //@RequestBody JSONObject object
        //FilesDTO dto = object.toJavaObject(FilesDTO.class);
        filesService.save(dto);
        return new Result().ok(dto);
    }

    @PostMapping("/modifyFileName")
    @ApiOperation("修改文件名")
    public Result modifyFileName(@RequestBody FilesDTO dto){
        boolean suc =filesService.modifyFileName(dto);
        return new Result().ok(suc);
    }
    @PostMapping("/modifyFileStatus")
    @ApiOperation("修改文件状态")
    public Result modifyFileStatus(@RequestBody FilesDTO dto){
        boolean suc =filesService.modifyFileStatus(dto);
        return new Result().ok(suc);
    }
    @PostMapping("/modifyFileCategory")
    @ApiOperation("修改文件分类")
    public Result modifyFileCategory(@RequestBody FilesDTO dto){
        boolean suc =filesService.modifyFileCategory(dto);
        return new Result().ok(suc);
    }
    @PutMapping
    @ApiOperation("修改")
    public Result update(@RequestBody FilesDTO dto){
        filesService.update(dto);

        return new Result().ok(dto);
    }

    @DeleteMapping
    @ApiOperation("删除")
    public Result delete(@RequestBody String[] ids){
        filesService.delete(ids);

        return new Result().ok(ids);
    }

}