<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Services\User\HomeService;
use Illuminate\Http\Request;
use App\Http\Controllers\Core\Auth;
use App\Models\Fpdx\RoomModel;
use Illuminate\Support\Facades\Redis;

/**
 * 个人主页接口
 * Class HomeController
 * @package App\Http\Controllers\User
 */
class HomeController extends Controller
{
    /**
     * 喜欢我的列表
     * @param  Request  $request
     * @return array
     * @deprecated
     */
    public function likeMeList(Request $request)
    {
        $uid = Auth::auth();
        $page = $request->get('page', 1);
        $pages = array(
            'page' => $page,
            'limit' => 20
        );
        $hs = new HomeService();
        $data = $hs->likeMeList($uid, $pages);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 我喜欢的列表
     * @param  Request  $request
     * @return array
     */
    public function likeList(Request $request)
    {
        $uid = Auth::auth();
        $page = $request->get('page', 1);
        $pages = array(
            'page' => $page,
            'limit' => 20
        );
        $hs = new HomeService();
        $data = $hs->likeList($uid, $pages);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => [
                'page' => $data['pages']['page'],
                'limit' => $data['pages']['limit'],
                'total' => $data['pages']['total'],
                'list' => $data['list']
            ],
        ]);
    }

    /**
     * 聊天列表数量
     * @return array
     */
    public function chatCount()
    {
        $uid = Auth::auth();
        $roomModel = new RoomModel();
        $cnt = $roomModel->getCountByType(2, $uid) ?? 0;
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => [
                'count' => $cnt
            ]
        ]);
    }

    /**
     * 匹配历史数量
     * @return array
     */
    public function pairCount()
    {
        $uid = Auth::auth();
        $roomModel = new RoomModel();
        $cnt = $roomModel->getCountByType(1, $uid) ?? 0;
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => [
                'count' => $cnt
            ]
        ]);
    }

    /**
     * 看过我的人数
     */
    public function lastLookMe()
    {
        $uid = Auth::auth();
        $hs = new HomeService();
        $cnt = $hs->lastLookMe($uid);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => [
                'cnt' => $cnt
            ]
        ]);
    }

    /**
     * 获取未解锁的「心动我的」卡片数量和最近三人的头像
     */
    public function unLookLikemeCnt()
    {
        $uid = Auth::auth();
        $hs = new HomeService();
        $data = $hs->unLookLikemeCnt($uid);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 判断是否是内测用户
     */
    public function isTestUser()
    {
        $uid = Auth::auth();
        $exists = Redis::sismember("fpdx_supervip_test", $uid);
        if (1 == $exists) {
            $istest = true;
        } else {
            $istest = false;
        }
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => [
                'istest' => $istest
            ]
        ]);
    }

    /**
     * 获取某人最近七天的热度
     */
    public function getLast7dayHot()
    {
        $uid = Auth::auth();
        $hs = new HomeService();
        $data = $hs->getLast7dayHot($uid);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 获取当前人气值
     */
    public function getPopularity()
    {
        $uid = Auth::auth();
        $hs = new HomeService();
        $data = $hs->getPopularity($uid);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 访客数据概览
     * @param  Request  $request
     * @return array
     */
    public function getVisitorOverView(Request $request)
    {
        $uid = Auth::auth();
        $hs = new HomeService();
        $data = $hs->getVisitorOverView($uid);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }

    /**
     * 访客数据列表
     * @param  Request  $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     * @deprecated
     */
    public function getVisitorList(Request $request)
    {
        $page = $request->get('page', 1);
        $pages = array(
            'page' => $page,
            'limit' => 20
        );
        $uid = Auth::auth();
        $hs = new HomeService();
        $data = $hs->getVisitorList($uid, $pages);
        return response([
            'code' => 200,
            'message' => 'success',
            'data' => $data
        ]);
    }
}
