<?php

namespace App\Http\Controllers\Share;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Core\Auth;
use App\Services\Share\GteamService;

class GteamController extends Controller
{
    /**
     * 检验邀请
     * @param  int  $invite_id
     * @return array
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function check(int $invite_id)
    {
        $uid = Auth::auth();
        $gs = new GteamService();
        $data = $gs->check($uid, $invite_id);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * vip邀请助力
     * @param  int  $invite_id
     * @return array
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function vipCheck(int $invite_id)
    {
        $uid = Auth::auth();
        $gs = new GteamService();
        $data = $gs->vipCheck($uid, $invite_id);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 获取助力的气泡
     * @param  int  $activity_id
     * @return array
     */
    public function lastInvite(int $activity_id)
    {
        $gs = new GteamService();
        $data = $gs->lastInvite($activity_id);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 获取最近的助力记录
     * @param  int  $invite_id
     * @return array
     */
    public function history(int $invite_id)
    {
        $gs = new GteamService();
        $data = $gs->history($invite_id);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 匹配成功率分享完成列表
     * @param  Request  $request
     * @return array
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function succlist(Request $request)
    {
        $uid = Auth::auth();
        $page = $request->get('page') ?? 1;
        $pages = array(
            'limit' => 20,
            'page' => $page
        );
        $gs = new GteamService();
        $data = $gs->succlist($uid, $pages);
        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }
}
