package com.common.controller;


import com.common.entity.DeviceDevice;
import com.common.service.DeviceDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/devices")
public class DeviceDeviceController {

    @Autowired
    private DeviceDeviceService deviceDeviceService;

    @GetMapping("/{id}")
    public DeviceDevice getById(@PathVariable Integer id) {
        System.out.println("device_id："+id.toString());
        DeviceDevice deviceDevice=deviceDeviceService.getById(id);
        System.out.println("deviceDeviceService："+deviceDevice.toString());
        return deviceDeviceService.getById(id);
    }

    @GetMapping
    public List<DeviceDevice> getAll() {
        return deviceDeviceService.getAll();
    }

    @GetMapping("/search")
    public List<DeviceDevice> searchByName(@RequestParam String name) {
        return deviceDeviceService.getByNameLike(name);
    }

    @GetMapping("/ip/{ip}")
    public List<DeviceDevice> getByIp(@PathVariable String ip) {

        List<DeviceDevice> deviceDevicelist =deviceDeviceService.getByIpSafely(ip);
        System.out.println("deviceDeviceService："+deviceDevicelist.get(0).toString());

        return deviceDeviceService.getByIpSafely(ip);
    }

    @GetMapping("/monitoring")
    public List<DeviceDevice> getMonitoringDevices() {
        return deviceDeviceService.getMonitoringDevices();
    }
}