package com.ruoyi.demo.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.demo.entity.Equipment;
import com.ruoyi.demo.entity.vo.EquipmentVo;
import com.ruoyi.demo.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/equimpent")
@RestController
public class EquipmentController {
    @Autowired
    EquipmentService equipmentService;
    @PostMapping("/addEquipment")
    public R addEquipment(@Validated(value = {AddGroup.class}) EquipmentVo equipmentVo){
        equipmentService.addEquipment(equipmentVo);
        return R.ok();
    }

    @PutMapping("/updateEquipment")
    public R updateEquipment(@Validated(value = {AddGroup.class})EquipmentVo equipmentVo){
        equipmentService.updateEquipment(equipmentVo);
        return R.ok();
    }

    @GetMapping("/getEquipment")
    public R getEquipment(String equipmentId){
        Equipment equipment = equipmentService.getEquipment(equipmentId);
        return R.ok(equipment);
    }

    @DeleteMapping("/deleteEquipment")
    public R deleteEquipment(String[] equipmentIds){
        equipmentService.deleteEquipment(equipmentIds);
        return R.ok();
    }

    /*获得该设备的广告计划*/
    @GetMapping("/getEquipmentBySelect")
    public R getEuipmentPlanList(EquipmentVo equipmentVo){
        PageInfo<Equipment> equipments = equipmentService.getEquipmentBySelect(equipmentVo);
        return R.ok(equipments);
    }

    /*找到未分组的设备*/
    @GetMapping("/getEquipmentBySelect")
    public R getEquipmentBySelect(EquipmentVo equipmentVo){
        PageInfo<Equipment> equipments = equipmentService.getEquipmentBySelect(equipmentVo);
        return R.ok(equipments);
    }

    /*确认添加*/
    @PostMapping("/addStoreEquipment")
    public R addStoreEquipment(EquipmentVo equipmentVo){
        equipmentService.addStoreEquipment(equipmentVo);
        return R.ok();
    }

    /*查看store下已有的设备*/
    @GetMapping("/getEquipmentByStoreId")
    public R getEquipmentByStoreId(EquipmentVo equipmentVo){
        PageInfo<Equipment> equipments = equipmentService.getEquipmentByStoreId(equipmentVo);
        return R.ok(equipments);
    }
}
