package com.bonus.canteen.core.device.manage.controller.deprecated;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.bonus.canteen.core.device.manage.controller.deprecated.vo.BasicsAppUpdateVo;
import com.bonus.canteen.core.device.manage.dto.BasicsAppUpdateDTO;
import com.bonus.canteen.core.device.manage.model.BasicsAppUpdate;
import com.bonus.canteen.core.device.manage.service.BasicsAppUpdateService;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/** @deprecated */
@RestController
@Api(
   value = "App更新",
   tags = {"App更新模块"}
)
@RequestMapping({"/api/v1/android/update"})
@Deprecated
public class BasicsAppUpdateController {
   @Autowired
   @Lazy
   BasicsAppUpdateService basicsAppUpdateService;

   @ApiOperation(
      value = "更新app包",
      notes = "查询条件设备版本号"
   )
   @PostMapping({"/saveUpdateApp"})
   public AjaxResult saveUpdateApp(@RequestHeader Map<String, String> headers, @RequestBody BasicsAppUpdateDTO dto) {
      this.basicsAppUpdateService.saveAppVersion(dto);
      return AjaxResult.success();
   }

   @ApiOperation(
      value = "获取当前版本",
      notes = "查询app当前版本"
   )
   @GetMapping({"/getnowappversion"})
   public AjaxResult getnowappversion(@RequestHeader Map<String, String> headers, String content) {
      BasicsAppUpdate basicsAppUpdate = JSON.parseObject(content, BasicsAppUpdate.class);
      basicsAppUpdate = this.basicsAppUpdateService.appNowVersion(basicsAppUpdate.getSourceType(), (String)null);
      if (basicsAppUpdate == null) {
         basicsAppUpdate = new BasicsAppUpdate();
      }

      BasicsAppUpdateVo basicsAppUpdateVo = BeanUtil.copyProperties(basicsAppUpdate, BasicsAppUpdateVo.class, new String[0]);
      return AjaxResult.success(basicsAppUpdateVo);
   }
}
