package com.bonus.material.upOrDown.equipment.controller;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.upOrDown.equipment.domain.EquipmentEntity;
import com.bonus.material.upOrDown.equipment.service.UpOrDownEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 30791
 * @version 1.0
 * Create by 2025/11/16 14:11
 */
@RestController
@RequestMapping("/upOrDown/equipment")
@Api(value = "装备上下架", tags = "装备上下架")
public class UpOrDownEquipmentController  extends BaseController {

    @Resource
    private UpOrDownEquipmentService upOrDownEquipmentService;

    @ApiOperation(value = "装备上架列表")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentEntity entity) {
        try {
            startPage();
            List<EquipmentEntity> list = upOrDownEquipmentService.list(entity);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }


    /**
     * 下架装备列表
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "下架装备列表")
    @GetMapping("/downEquipmentList")
    public TableDataInfo downList(EquipmentEntity entity) {
        try {
            startPage();
            List<EquipmentEntity> list = upOrDownEquipmentService.listByDown(entity);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }





    /**
     * 下架装备
     */
    @ApiOperation(value = "下架装备")
    @PostMapping("/down/{equipmentId}")
    public AjaxResult down(@PathVariable("equipmentId") Long equipmentId)
    {
        upOrDownEquipmentService.downEquipmentById(equipmentId);
        return AjaxResult.success();
    }

    /**
     * 批量上架
     * @param entity
     * @return
     */
    @ApiOperation(value = "批量上架装备")
    @PostMapping("/batch/up")
    public AjaxResult upToolBatch(@RequestBody List<EquipmentEntity> entity) {
        if (CollectionUtils.isEmpty(entity)) {
            return AjaxResult.warn("请选择要批量上架的装备");
        }
        return upOrDownEquipmentService.upEquipmentBatch(entity);
    }

    /**
     * 批量下架
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量下架装备")
    @PostMapping("/batch/down")
    public AjaxResult downToolBatch(@RequestBody List<Long> ids) {
        upOrDownEquipmentService.downEquipmentBatch(ids);
        return AjaxResult.success();
    }



}
