package com.zcloud.basic.info.web;


import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.basic.info.api.ImgFilesServiceI;
import com.zcloud.basic.info.dto.ImgFilesAddCmd;
import com.zcloud.basic.info.dto.ImgFilesPageQry;
import com.zcloud.basic.info.dto.ImgFilesQryCmd;
import com.zcloud.basic.info.dto.ImgFilesUpdateCmd;
import com.zcloud.basic.info.dto.clientobject.ImgFilesCO;
import com.zcloud.basic.info.dto.clientobject.ImgFilesBase64CO;
import com.zcloud.basic.info.dto.clientobject.ImgFilesInfoCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;

/**
* web-adapter
* @Author zhangyue
* @Date 2025-10-30 16:10:05
*/
@Api(tags = "图片信息表")
@RequestMapping("/${application.gateway}/imgFiles")
@RestController
@AllArgsConstructor
public class ImgFilesController {
    private final ImgFilesServiceI imgFilesService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<ImgFilesCO> add(@Validated ImgFilesAddCmd cmd) {
        return imgFilesService.add(cmd);
    }

    @ApiOperation("批量新增")
    @PostMapping("/batchSave")
    public SingleResponse<ImgFilesInfoCO> batchAdd(@Validated ImgFilesAddCmd cmd) {
        return imgFilesService.batchAdd(cmd);
    }



    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<ImgFilesCO> page(@RequestBody ImgFilesPageQry qry) {
        return imgFilesService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @GetMapping("/listAll")
    public MultiResponse<ImgFilesCO> listAll(ImgFilesQryCmd imgFilesQryCmd) {
        return imgFilesService.listAll(imgFilesQryCmd);
    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<ImgFilesCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(new ImgFilesCO());
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Response removeFile(@RequestParam String filePath) {
        imgFilesService.removeFile(filePath);
        return Response.buildSuccess();
    }

    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam Long[] ids) {
        imgFilesService.removeBatch(ids);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody ImgFilesUpdateCmd imgFilesUpdateCmd) {
        imgFilesService.edit(imgFilesUpdateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("获取图片前缀地址")
    @GetMapping("/getImagePath")
    public SingleResponse<String> getImagePath() {
        return SingleResponse.of(imgFilesService.getImagePath());
    }

    @ApiOperation("所有数据(base64格式)")
    @GetMapping("/listAllBase64")
    public MultiResponse<ImgFilesBase64CO> listAllBase64(ImgFilesQryCmd imgFilesQryCmd) {
        return imgFilesService.listAllBase64(imgFilesQryCmd);
    }
}

