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

import com.neusoft.smart.pos.dto.ota.request.UpgradeHistoryQueryRequest;
import com.neusoft.smart.pos.dto.ota.request.UpgradeHistoryRequest;
import com.neusoft.smart.pos.dto.ota.response.UpgradeHistoryExtResponse;
import com.neusoft.smart.pos.dto.ota.response.UpgradeHistoryResponse;
import com.neusoft.smart.pos.framework.bean.PaginationExtendBean;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.ota.service.UpgradeHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@Api(value = "更新历史管理restful接口", description = "更新历史管理restful接口")
public class UpgradeHistoryController {
	
	@Autowired
	private UpgradeHistoryService upgradeHistoryService;
	
	/**
	 * @param upgradeHistoryRequest
	 * @param bindingResult
	 * @return
	 */
	@PostMapping("/upgradeHistory")
	@ApiOperation(value = "更新历史添加接口", notes = "更新历史添加接口")
	public ResponseData<UpgradeHistoryResponse> create(@Valid @RequestBody UpgradeHistoryRequest upgradeHistoryRequest, BindingResult bindingResult) {
		return new ResponseData<>(upgradeHistoryService.create(upgradeHistoryRequest));
	}
	
	
	@ApiOperation(value = "分页查询更新历史接口", notes = "分页查询更新历史接口")
	@PostMapping("/upgradeHistories")
	public ResponseData<PaginationExtendBean<UpgradeHistoryResponse>> groupList(@RequestBody UpgradeHistoryQueryRequest upgradeHistoryQueryRequest) {
		PaginationExtendBean<UpgradeHistoryResponse> paginationExtendBean = new PaginationExtendBean<>();
		paginationExtendBean.setRows(upgradeHistoryService.getList(upgradeHistoryQueryRequest));
		paginationExtendBean.setTotal(upgradeHistoryService.queryCount(upgradeHistoryQueryRequest));
		return new ResponseData<>(paginationExtendBean);
	}
	
	@GetMapping("/upgradeHistories/lastUpdateTime")
	@ApiOperation(value = "通过设备集合查询最新更新时间接口", notes = "通过设备集合查询最新更新时间接口")
	public ResponseData<List<UpgradeHistoryExtResponse>> getLastUpdateTime(@RequestParam("deviceIds") List<Integer> deviceIds) {
		return new ResponseData<>(upgradeHistoryService.getLastUpdateTime(deviceIds));
	}
	
}
