package com.sptg.gateway.controller.device;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.device.api.constant.DeviceSecurityToken;
import com.sptg.device.api.dto.DeviceOptionsDto;
import com.sptg.device.api.entity.DeviceOptions;
import com.sptg.device.api.feigns.DeviceOptionsFeign;
import lombok.AllArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@AllArgsConstructor
public class DeviceOptionsController {
    private final DeviceOptionsFeign deviceOptionsFeign;

    @PostMapping(value = "/device/options/add")
    @Security(token = DeviceSecurityToken.DEVICE_INFO_UPDATE,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> add(DeviceOptionsDto deviceOptionsDto){
        return new ResultBean<>(ResultEnum.SUCCESS,this.deviceOptionsFeign.add(deviceOptionsDto));
    }

    @PostMapping(value = "/device/options/edit")
    @Security(token = DeviceSecurityToken.DEVICE_INFO_UPDATE,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> update(DeviceOptionsDto deviceOptionsDto){
        return new ResultBean<>(ResultEnum.SUCCESS,this.deviceOptionsFeign.edit(deviceOptionsDto));
    }

    @GetMapping(value = "/device/options/getByDeviceId/{deviceId}")
    public ResultBean<DeviceOptions> getByDeviceId(@PathVariable(value = "deviceId") Long deviceId){
        if (deviceId == null){
            return new ResultBean<>(ResultEnum.NOT_FIND);
        }
        DeviceOptions deviceOptions = this.deviceOptionsFeign.getByDeviceId(deviceId);
        return new ResultBean<>(ResultEnum.SUCCESS,deviceOptions);
    }
}
