package com.sptg.permissions.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.PageBean;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.CommonConstant;
import com.sptg.common.core.util.CommonUtil;
import com.sptg.permissions.api.dto.AccountDto;
import com.sptg.permissions.api.dto.AccountOauthDto;
import com.sptg.permissions.api.entity.Account;
import com.sptg.permissions.api.entity.AccountOauth;
import com.sptg.permissions.api.entity.Role;
import com.sptg.permissions.api.feigns.AccountOauthFeign;
import com.sptg.permissions.api.feigns.AccountOauthFeign;
import com.sptg.permissions.biz.service.AccountOauthServiceInterface;
import com.sptg.permissions.biz.service.AccountServiceInterface;
import com.sptg.permissions.biz.service.RoleServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * title: AccountOauthController
 * package: com.sptg.permissions.biz.controller
 * description: 账号授权-控制器
 *
 *
 *
 */
@RestController
@RequiredArgsConstructor
public class AccountOauthController implements AccountOauthFeign {

    private final AccountOauthServiceInterface accountOauthServiceInterface;
    private final AccountServiceInterface accountServiceInterface;

    @Override
    @PostMapping(value = "/account/oauth/pagingQuery")
    public ResultBean<Page> pagingQuery(@RequestBody PageBean<AccountOauth,AccountOauthDto> pageBean) {
        Page<AccountOauth> page = this.accountOauthServiceInterface.pagingQuery(pageBean);
        return new ResultBean<>(ResultEnum.SUCCESS,page);
    }

    @Override
    @PostMapping(value = "/account/oauth/getByUuIdAndSource")
    public ResultBean<AccountOauth> getByUuIdAndSource(@RequestBody AccountOauthDto dto) {
        AccountOauth oauth = this.accountOauthServiceInterface.selectByUuIdAndSource(dto.getUuId(), dto.getSource());
        return new ResultBean<>(ResultEnum.SUCCESS,oauth);
    }

    @Override
    @PostMapping(value = "/account/oauth/bind")
    public ResultBean<Boolean> bindUser(@RequestBody AccountOauthDto dto) {
        //  获取账号信息
        Boolean result = this.accountOauthServiceInterface.bindUser(dto);
        return new ResultBean<>(ResultEnum.SUCCESS,result);
    }

    @Override
    @PostMapping(value = "/account/oauth/untie")
    public ResultBean<Boolean> untieUser(@RequestBody AccountOauthDto dto) {
        Boolean result = this.accountOauthServiceInterface.untieUser(dto);
        return new ResultBean<>(ResultEnum.SUCCESS,result);
    }

}
