package com.fuyuanshen.app.controller;

import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
import com.fuyuanshen.app.domain.dto.AppFileDto;
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
import com.fuyuanshen.app.service.AppFileService;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.web.core.BaseController;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * APP 文件管理
 * @date 2025-06-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/file")
public class AppFileController extends BaseController {

    private final AppFileService appFileService;


    /**
     * 查询文件列表
     */
    @GetMapping("/list")
    public R<List<AppFileVo>> list(AppBusinessFileBo bo) {
        return R.ok(appFileService.list(bo));
    }


    /**
     * 上传文件
     */
    @PostMapping("/upload")
    public R<Void> upload(@Validated @ModelAttribute AppFileDto bo) throws IOException {
        return toAjax(appFileService.add(bo));
    }


    /**
     * 文件删除
     */
    @DeleteMapping("/delete/{ids}")
    public R<Void> delete(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        if(ids == null || ids.length == 0){
            return R.fail("请选择要删除的文件");
        }
        return toAjax(appFileService.delete(ids));
    }

}
