<?php

namespace App\Http\Services\V1_1;

use App\Generated\V1_1\Messages\UserHome\GetPopularityMessage;
use App\Generated\V1_1\Messages\UserHome\GetVisitorListMessage;
use App\Generated\V1_1\Messages\UserHome\GetLikeMeListMessage;
use App\Generated\V1_1\Messages\UserHome\GetMyLikeListMessage;
use App\Generated\V1_1\Messages\UserHome\RemindComplementCardMessage;
use App\Http\Controllers\Core\Auth;
use App\Managers\UserManager;
use App\Services\Home\FeedService;
use App\Services\User\HomeService;

class UserHomeService
{

    protected $userManager;

    public function __construct(UserManager $userManager)
    {
        $this->userManager = $userManager;
    }


    /**
     * 获取喜欢我的列表
     * @param  GetLikeMeListMessage  $message
     */
    public function getLikeMeList(GetLikeMeListMessage $message)
    {
        $uid = Auth::auth();
        $page = $message->getPage() ?? 1;
        $limit = $message->getLimit() ?? 20;
        $data = $this->userManager->getLikeMeList($uid, $page, $limit);
        $message->setResponse($data);
    }


    /**
     * 获取我喜欢的列表
     * @param  GetMyLikeListMessage  $message
     */
    public function getMyLikeList(GetMyLikeListMessage $message)
    {
        $uid = Auth::auth();
        $page = $message->getPage() ?? 1;
        $limit = $message->getLimit() ?? 20;
        $data = $this->userManager->getMyLikeList($uid, $page, $limit);
        $message->setResponse($data);
    }


    /**
     * 获取访客列表
     * @param  GetVisitorListMessage  $message
     */
    public function getVisitorList(GetVisitorListMessage $message)
    {
        $page = $message->getPage() ?? 1;
        $limit = $message->getLimit() ?? 20;
        $uid = $message->getUid() ?? Auth::auth();
        $data = $this->userManager->getVisitorList($uid, $page, $limit);
        $message->setResponse($data);
    }


    /**
     * 提醒TA补全信息
     * @param  RemindComplementCardMessage  $message
     */
    public function remindComplementCard(RemindComplementCardMessage $message)
    {
        $uid = Auth::auth();
        $type = $message->getType();
        $remind_uid = $message->getRemind_uid();
        $feedService = new FeedService();
        $feedService->remindType4($uid, $remind_uid, $type);
    }

    public function getPopularity(GetPopularityMessage $message)
    {
        $uid = Auth::auth();
        $hus = new HomeService();
        $data = $hus->getPopularity($uid);
        $message->setResponse(
            $data['popularity_share_end_at'],
            $data['popularity_sign_end_at'],
            $data['popularity_supvip_endat'],
            $data['popularity'],
            $data['base']
        );
    }
}
