package com.tzld.piaoquan.api.controller.contentplatform;

import com.tzld.piaoquan.api.annotation.JwtIgnore;
import com.tzld.piaoquan.api.annotation.RateLimit;
import com.tzld.piaoquan.api.model.param.contentplatform.AccountForbiddenParam;
import com.tzld.piaoquan.api.model.param.contentplatform.AccountListParam;
import com.tzld.piaoquan.api.model.param.contentplatform.AccountLoginParam;
import com.tzld.piaoquan.api.model.param.contentplatform.AccountSaveParam;
import com.tzld.piaoquan.api.model.vo.contentplatform.AccountLoginVO;
import com.tzld.piaoquan.api.model.vo.contentplatform.AccountVO;
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformAccountService;
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
import com.tzld.piaoquan.growth.common.utils.page.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/contentPlatform/account")
@CrossOrigin(origins = "*")
public class ContentPlatformAccountController {

    @Autowired
    ContentPlatformAccountService accountService;

    @ApiOperation(value = "手机号登录")
    @PostMapping("/login")
    @JwtIgnore
//    @RateLimit(timeWindow = 1800, maxRequests = 5, message = "请求过于频繁，请稍后再试")
    public CommonResponse<AccountLoginVO> login(@RequestBody AccountLoginParam param) {
        return CommonResponse.success(accountService.login(param));
    }

    //@ApiOperation(value = "发送短信验证码")
    //@PostMapping("/sendMessageVerifyCode")
    //@JwtIgnore
    //@RateLimit(timeWindow = 3600, maxRequests = 3, message = "请求过于频繁，请稍后再试")
    //public CommonResponse<Void> sendMessageVerifyCode(@RequestBody AccountSendMessageParam param) {
    //    accountService.sendMessageVerifyCode(param);
    //    return CommonResponse.success();
    //}

    @ApiOperation(value = "分页获取账户")
    @PostMapping(value = "/list")
    public CommonResponse<Page<AccountVO>> pageAccount(@RequestBody AccountListParam param) {
        return CommonResponse.success(accountService.pageAccount(param));
    }

    @ApiOperation(value = "账户封禁")
    @PostMapping(value = "/forbidden")
    public CommonResponse<Void> accountForbidden(@RequestBody AccountForbiddenParam param) {
        accountService.accountForbidden(param);
        return CommonResponse.success();
    }

    @ApiOperation(value = "账户创建/更新")
    @PostMapping(value = "/save")
    public CommonResponse<Void> saveAccount(@RequestBody AccountSaveParam param) {
        accountService.saveAccount(param);
        return CommonResponse.success();
    }
}
