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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.neusoft.smart.pos.dto.ota.request.UpgradeHistoryQueryRequest;
import com.neusoft.smart.pos.dto.ota.response.ApkVersionStrategyDetailResponse;
import com.neusoft.smart.pos.framework.bean.PaginationExtendBean;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.gateway.service.OTAService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/unionService/OTA")
@Api(value = "OTA相关restful接口", description = "OTA相关restful接口")
public class OTAController {
	
	@Autowired
	private OTAService otaDevice;
	
	@ApiOperation(value = "设备升级历史接口", notes = "设备升级历史接口")
	@PostMapping("/upgradeHistories")
	public ResponseData<PaginationExtendBean<JSONObject>> upgradeHistories(@RequestBody UpgradeHistoryQueryRequest upgradeHistoryQueryReques) {
		return new ResponseData<>(otaDevice.queryHistoryList(upgradeHistoryQueryReques));
	}
	
	@ApiOperation(value = "查看升级策略详情接口", notes = "查看升级策略详情接口")
	@GetMapping("/upgradeStrategy/relation/{groupId}")
	public ResponseData<JSONArray> upgradeStrategies(@PathVariable Integer groupId) {
		return new ResponseData<>(otaDevice.getStrategyList(groupId));
	}
	
	@ApiOperation(value = "查看app升级策略详情接口", notes = "查看app升级策略详情接口")
	@GetMapping("/apkVersionStrategy/detail/{groupId}")
	public ResponseData<ApkVersionStrategyDetailResponse> getApkVersionStrategyDetail(@PathVariable Integer groupId) {
		return new ResponseData<>(otaDevice.getApkStrategyDetail(groupId));
	}
	
}
