package com.neusoft.smart.pos.gateway.controller;

import com.neusoft.smart.pos.dto.device.request.DeviceQueryRequest;
import com.neusoft.smart.pos.dto.device.request.DeviceRequest;
import com.neusoft.smart.pos.dto.device.request.DeviceStatusRequest;
import com.neusoft.smart.pos.dto.device.request.DeviceStoreRequest;
import com.neusoft.smart.pos.dto.device.response.DeviceResponse;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.gateway.service.DeviceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/unionService/device")
public class DeviceController {
	
	@Autowired
	private DeviceService deviceService;
	
	@PutMapping("")
	@ApiOperation(value = "设备修改接口", notes = "设备修改接口")
	public ResponseData<?> update(@RequestBody DeviceRequest deviceRequest) {
        return deviceService.update(deviceRequest);
	}
	
	@ApiOperation(value = "查询设备状态接口", notes = "查询设备状态接口")
	@PostMapping("/status")
	public ResponseData<?> getDeviceStatus(@RequestBody DeviceQueryRequest deviceQueryRequest) {
		return new ResponseData<>(deviceService.queryDeviceStatus(deviceQueryRequest));
	}
	
	@PostMapping("/batch")
	@ApiOperation(value = "设备批量添加接口", notes = "设备批量添加接口")
	public ResponseData<List<DeviceResponse>> createByBatch(@RequestBody List<DeviceRequest> deviceRequestList) {
		return deviceService.createByBatch(deviceRequestList);
	}
	
	@PostMapping()
	@ApiOperation(value = "设备添加接口", notes = "设备添加接口")
	public ResponseData<DeviceResponse> create(@Valid @RequestBody DeviceRequest deviceRequest,
			BindingResult bindingResult) {
		return deviceService.create(deviceRequest);
	}
	
	@PutMapping("/store")
	@ApiOperation(value = "设置设备归属门店接口", notes = "设置设备归属门店接口")
	ResponseData<DeviceResponse> updateStore(@Valid @RequestBody DeviceStoreRequest deviceStoreRequest, BindingResult bindingResult) {
		return deviceService.updateStore(deviceStoreRequest);
	}
	
	@PutMapping("/status")
	@ApiOperation(value = "修改设备状态接口", notes = "修改设备状态接口")
	public ResponseData<?> updateStatus(@Valid @RequestBody DeviceStatusRequest deviceStatusRequest,
			BindingResult bindingResult) {
		return deviceService.updateStatus(deviceStatusRequest);
	}
}
