package org.springblade.openinterface.facedevice.qinlin.api;

import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.openinterface.facedevice.qinlin.beans.QinLinApiResultBean;
import org.springblade.openinterface.facedevice.qinlin.vo.QLinQuery;
import org.springblade.openinterface.facedevice.qinlin.vo.QLinUser;
import org.springblade.openinterface.facedevice.qinlin.util.QinLinHttpUtil;
import org.springblade.openinterface.facedevice.qinlin.vo.QLinUserDevice;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zwx
 * @create 2021/1/13 23:07
 */
@RestController
@AllArgsConstructor
@RequestMapping("qinlin")
@Api(value = "亲邻设备接口", tags = "亲邻设备接口")
public class QinLinController {

	private QinLinHttpUtil qinLinHttpUtil;

	@PostMapping("/addUser")
	public R addUser(@RequestBody QLinUser qLinUser){
		QinLinApiResultBean qinLinApiResultBean = qinLinHttpUtil.addUser(qLinUser);
		Integer code = qinLinApiResultBean.getCode();
		if(code.equals(0)){ //成功
			return R.success("添加成功");
		}else{
			return R.fail("添加成功");
		}
	}

	@PostMapping("/deleteUser")
	public R deleteUser(@RequestBody QLinUser qLinUser){
		QinLinApiResultBean qinLinApiResultBean = qinLinHttpUtil.deleteUser(qLinUser);
		Integer code = qinLinApiResultBean.getCode();
		if(code.equals(0)){ //成功
			return R.success("删除成功");
		}else{
			return R.fail("删除失败");
		}
	}

	@PostMapping("/remoteOpenDoor")
	public R remoteOpenDoor(@RequestBody QLinUserDevice qLinUserDevice){
		QinLinApiResultBean qinLinApiResultBean = qinLinHttpUtil.remoteOpenDoor(qLinUserDevice);
		Integer code = qinLinApiResultBean.getCode();
		if(code.equals(0)){ //成功
			return R.success("删除成功");
		}else{
			return R.fail("删除失败");
		}
	}

	@PostMapping("/getLogs")
	public R getLogs(@RequestBody QLinQuery qLinQuery){
		QinLinApiResultBean qinLinApiResultBean = qinLinHttpUtil.getLogs(qLinQuery);
		Integer code = qinLinApiResultBean.getCode();
		if(code.equals(0)){ //成功
			return R.success("删除成功");
		}else{
			return R.fail("删除失败");
		}
	}
}
