package com.sqx.modules.userExtension.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.userExtension.entity.UserExtension;
import com.sqx.modules.userExtension.service.UserExtensionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/userExtension/")
@Api(value = "推广申请", tags = {"用户推广申请"})
public class UserExtensionController {

    @Autowired
    UserExtensionService extensionService;

    @Login
    @ApiOperation("用户申请成为推广员")
    @PostMapping("addUserExtension")
    public Result addUserExtension(UserExtension userExtension, @RequestAttribute("userId") Long userId) {
        userExtension.setUserId(userId);
        return extensionService.addUserExtension(userExtension);
    }

    @Login
    @ApiOperation("用户修改申请信息")
    @PostMapping("updateUserExtension")
    public Result updateUserExtension(UserExtension userExtension, @RequestAttribute("userId") Long userId) {
        userExtension.setUserId(userId);
        return extensionService.updateUserExtension(userExtension);
    }

    @Login
    @ApiOperation("获取用户申请信息")
    @GetMapping("getUserExtensionInfo")
    public Result getUserExtensionInfo(@RequestAttribute("userId") Long userId) {
        return Result.success().put("data", extensionService.getUserExtensionInfo(userId));
    }
}
