package com.mcwl.web.controller.communityCenter;


import com.mcwl.common.constant.HttpStatus;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.common.utils.StringUtils;
import com.mcwl.communityCenter.domain.Community;
import com.mcwl.communityCenter.service.InviteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * 邀请
 */
@Api(tags = "社区邀请")
@RestController
@RequestMapping("invite")
@RequiredArgsConstructor
@Valid
public class InviteController {

    private final InviteService inviteService;

    /**
     * 邀请码链接
     */
    @ApiOperation(value = "邀请码链接")
    @GetMapping("inviteCode")
    public R<String> inviteCode(@NotNull(message = "社区不能为空")
                                 @ApiParam(value = "社区", required = true)
                                 Long communityId) {
        // 获取邀请码链接
        String inviteCode = inviteService.getInviteCode(communityId);
        if (StringUtils.isBlank(inviteCode)) {
            return R.fail(HttpStatus.SHOW_ERROR_MSG,"获取邀请码失败");
        }
        return R.ok(inviteCode);
    }

    /**
     * 接受邀请
     */
    @ApiOperation(value = "接受邀请")
    @GetMapping("acceptInvite")
    @Valid
    public R<Object> acceptInvite(@NotNull(message = "社区不能为空")
                                   @ApiParam(value = "社区", required = true)
                                   Long communityId,
                                   @NotBlank(message = "邀请码不能为空")
                                   @ApiParam(value = "邀请码", required = true)
                                   String inviteCode) {

        return inviteService.acceptInvite(communityId, inviteCode);
    }


}
