package com.github.wxiaoqi.security.admin.rest;

import com.github.wxiaoqi.security.admin.vo.InviteMemberVo;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.auth.client.jwt.UserAuthUtil;
import com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.admin.biz.AppUserRelationBiz;
import com.github.wxiaoqi.security.admin.entity.AppUserRelation;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;

@RestController
@RequestMapping("relation")
public class AppUserRelationController extends BaseController<AppUserRelationBiz,AppUserRelation> {

    @Autowired
    private UserAuthUtil userAuthUtil;

    @Autowired
    private UserAuthConfig userAuthConfig;


    @RequestMapping(value = "app/unauth/small/share",method = RequestMethod.GET)
    @ApiModelProperty("小程序分享绑定")
    public ObjectRestResponse share(
            @RequestParam(value = "userid",defaultValue = "0")Integer userid,
            @RequestParam(value = "pid",defaultValue = "0")Integer pid,
            @RequestParam(value = "platform_userid",defaultValue = "0")Integer platform_userid
    ){
        return baseBiz.shareParentByUserId(userid,pid,platform_userid);
    }

    @RequestMapping(value = "/bind",method = RequestMethod.POST)
    @ApiModelProperty("app分享绑定")
    public ObjectRestResponse bind(
            @RequestParam(value = "code",defaultValue = "")String code,
            HttpServletRequest request){
        try {
            //屏蔽分享绑定
        /*Integer userid = Integer.parseInt(userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request)).getId());
        return baseBiz.appBindRelation(userid,code);*/
        return ObjectRestResponse.succ();
        } catch (Exception e) {
            e.printStackTrace();
            throw new BaseException(e);
        }
    }

    @ApiOperation("查询邀请的成员")
    @GetMapping("/pages")
    public ObjectRestResponse<InviteMemberVo> findInviteMemberByActivitState(@RequestParam(value = "state",required = false) Integer state,
                                                                             @RequestParam("page") Integer page,
                                                                             @RequestParam("limit") Integer limit,
                                                                             HttpServletRequest request){
        try {
            IJWTInfo infoFromToken = userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request));
            InviteMemberVo inviteMemberVo =  baseBiz.findInviteMemberByActivitState(Integer.valueOf(infoFromToken.getId()),state,page,limit);
          return ObjectRestResponse.succ(inviteMemberVo);
        } catch (Exception e) {
            throw new BaseException(e);
        }
    }

}