package com.sptg.device.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.device.api.dto.DeviceRemoteInfoDto;
import com.sptg.device.api.entity.DeviceRemoteInfo;
import com.sptg.device.api.feigns.DeviceRemoteInfoFeign;
import com.sptg.device.biz.service.DeviceRemoteInfoServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * @author zwx
 * @create 2020/9/29 17:43
 */
@RestController
@RequiredArgsConstructor
public class DeviceRemoteInfoController implements DeviceRemoteInfoFeign {

    private final DeviceRemoteInfoServiceInterface deviceRemoteInfoServiceInterface;

    @Override
    @PostMapping(value = "/deviceRemoteInfo/pagingQuery")
    public ResultBean<Page> pagingQuery(@RequestBody DeviceRemoteInfoDto dto) {
        Page<DeviceRemoteInfo> deviceRemoteInfoPage = this.deviceRemoteInfoServiceInterface.pagingQuery(dto);
        return new ResultBean<>(ResultEnum.SUCCESS, deviceRemoteInfoPage);
    }

    @Override
    @PostMapping(value = "/deviceRemoteInfo/add")
    public ResultBean<Boolean> add(@RequestBody DeviceRemoteInfoDto dto) {
        String serialNumber = dto.getSerialNumber();
        Assert.notNull(serialNumber != null, "设备序列号不能为空");
        return this.deviceRemoteInfoServiceInterface.add(dto);
    }

    @Override
    @PostMapping(value = "/deviceRemoteInfo/edit")
    public ResultBean<Boolean> edit(@RequestBody DeviceRemoteInfo deviceRemoteInfo) {
        Long id = deviceRemoteInfo.getId();
        Assert.notNull(id, "设备远程信息ID不能为空");
        return this.deviceRemoteInfoServiceInterface.edit(deviceRemoteInfo);
    }

    @Override
    @PostMapping(value = "/deviceRemoteInfo/findDeviceRemoteInfo")
    public DeviceRemoteInfo findDeviceRemoteInfo(@RequestBody DeviceRemoteInfoDto dto) {
        Long id = dto.getId();
        String serialNumber = dto.getSerialNumber();
        Assert.isTrue(id != null || serialNumber != null, "设备远程信息ID或者设备序列号不能为空");
        return deviceRemoteInfoServiceInterface.findDeviceRemoteInfo(dto);
    }

    @Override
    @GetMapping(value = "/deviceRemoteInfo/getEntityBySerialNumber/{serialNumber}")
    public DeviceRemoteInfo getBySerialNumber(@PathVariable(value = "serialNumber") String serialNumber) {
        Assert.notNull(serialNumber, "设备序列号不能为空");
        DeviceRemoteInfo deviceRemoteInfo = this.deviceRemoteInfoServiceInterface.getBySerialNumber(serialNumber);
        return deviceRemoteInfo;
    }

    @Override
    @GetMapping(value = "/deviceRemoteInfo/getEntityById/{id}")
    public DeviceRemoteInfo getById(@PathVariable(value = "id") Long id) {
        Assert.notNull(id, "设备远程信息ID不能为空");
        DeviceRemoteInfo deviceRemoteInfo = this.deviceRemoteInfoServiceInterface.getById(id);
        return deviceRemoteInfo;
    }

    @Override
    @PostMapping(value = "/deviceRemoteInfo/delete")
    public ResultBean<Boolean> delete(@RequestBody DeviceRemoteInfoDto dto) {
        return this.deviceRemoteInfoServiceInterface.delete(dto);
    }
}
