package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.ShopVersion;
import cn.wisenergy.model.dto.AccountInfoQuery;
import cn.wisenergy.service.app.AccountService;
import cn.wisenergy.web.common.BaseController;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 86187
 */
@Api(tags = "账户管理")
@RestController
@Slf4j
public class AccountController extends BaseController {
    @Autowired
    private AccountService accountService;

    @ApiOperation(value = "获取账户信息", notes = "获取账户信息", httpMethod = "GET")
    @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String")
    @GetMapping("/account/getByUserId")
    public R<AccountInfo> getByUserId(String userId) {
        return accountService.getByUserId(userId);
    }


    @ApiOperation(value = "获取账户分页列表", notes = "获取账户分页列表", httpMethod = "GET")
    @ApiImplicitParam(name = "query", value = "查询条件", dataType = "AccountInfoQuery")
    @GetMapping("admin/account/getList")
    public R<PageInfo<AccountInfo>> getList(AccountInfoQuery query) {
        return accountService.getList(query);
    }


    @ApiOperation(value = "设置页-版本更新", notes = "设置页-版本更新", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "version", value = "版本号", dataType = "string", required = true),
            @ApiImplicitParam(name = "type", value = "类型 ios :1 安卓：2", dataType = "int", required = true)
    })
    @GetMapping("/account/version")
    public R<String> version(String version, Integer type) {
        if (StringUtils.isBlank(version) || null == type) {
            return R.error("入参不能为空!");
        }
        return accountService.updateVersion(version, type);
    }

    @ApiOperation(value = "ios/安卓包下载信息", notes = "ios/安卓包下载信息", httpMethod = "GET")
    @GetMapping("/account/download")
    public R<List<ShopVersion>> download() {
        return accountService.getVersion();
    }

}
