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

import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AccountInfo;
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.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

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


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


    @ApiOperation(value = "设置页-版本更新", notes = "设置页-版本更新", httpMethod = "GET")
    @ApiImplicitParam(name = "version", value = "版本号", dataType = "string")
    @GetMapping("/version")
    public R<String> version(String version) {
        if(StringUtils.isBlank(version)){
            return R.error("入参不能为空!");
        }
        return accountService.updateVersion(version);
    }

}
