package com.corewing.app.modules.admin.biz;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.corewing.app.common.Result;
import com.corewing.app.dto.biz.firmware.FirmwareBatchDeleteRequest;
import com.corewing.app.entity.Firmware;
import com.corewing.app.service.FirmwareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 固件管理
 */
@Controller
@RequestMapping("/biz/firmware")
public class BizFirmwareController {

    @Resource
    private FirmwareService firmwareService;


    /**
     * 固件管理首页
     * @return
     */
    @GetMapping("/index")
    public  String index() {
        return "admin/biz/firmware/index";
    }

    /**
     * 分页查询
     * @param firmware
     * @return
     */
    @GetMapping("/page")
    @ResponseBody
    public Result<Page<Firmware>> page(Firmware firmware) {
        return Result.success(firmwareService.page(firmware));
    }

    /**
     * 保存
     * @param firmware
     * @return
     */
    @PostMapping("/save")
    @ResponseBody
    public Result<String> save(@RequestBody Firmware firmware) {
        return Result.isBool(firmwareService.save(firmware));
    }

    /**
     * 更新
     * @param firmware
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    public Result<String> update(@RequestBody Firmware firmware) {
        return Result.isBool(firmwareService.updateById(firmware));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @ResponseBody
    public Result<Firmware> delete(String id) {
        return Result.isBool(firmwareService.removeById(id));
    }

    /**
     * 批量删除
     * @param firmwareBatchDeleteRequest
     * @return
     */
    @PostMapping("/batchDelete")
    @ResponseBody
    public Result<Firmware> batchDelete(@RequestBody FirmwareBatchDeleteRequest firmwareBatchDeleteRequest) {
        return Result.isBool(firmwareService.removeBatchByIds(firmwareBatchDeleteRequest.getIds()));
    }

    /**
     * 上传固件
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    @ResponseBody
    public Result<String> uploadFile(MultipartFile file) {
        return Result.success();
    }

}
