<?php

namespace App\Http\Controllers\Share;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Core\Auth;
use App\Services\Share\PopularitySharehelpService;
use Illuminate\Http\Request;

/**
 * Class PopularitySharehelpController
 * @package App\Http\Controllers\Share
 */
class PopularitySharehelpController extends Controller
{
    /**
     * 人气值分享助力
     * @param  int  $share_uid
     * @return array
     * @throws \App\Exceptions\AlertException
     */
    public function check(int $share_uid)
    {
        $uid = Auth::auth();
        $pshs = new PopularitySharehelpService();
        $data = $pshs->check($share_uid, $uid);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 助力页概览
     */
    public function helpOverView()
    {
        $uid = Auth::auth();
        $pshs = new PopularitySharehelpService();
        $data = $pshs->helpOverView($uid);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 加持中的助力
     * @param  Request  $request
     * @return array
     */
    public function inglist(Request $request)
    {
        $uid = Auth::auth();
        $page = $request->get('page') ?? 1;
        $pages = array(
            'limit' => 20,
            'page' => $page
        );
        $psgs = new PopularitySharehelpService();
        $data = $psgs->inglist($uid, $pages);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 失效的助力
     * @param  Request  $request
     * @return array
     */
    public function historylist(Request $request)
    {
        $uid = Auth::auth();
        $page = $request->get('page') ?? 1;
        $pages = array(
            'limit' => 20,
            'page' => $page
        );
        $popularityShareHelpService = new PopularitySharehelpService();
        $data = $popularityShareHelpService->historylist($uid, $pages);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }
}
