<?php

namespace App\Http\Controllers\Deed;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Core\Auth;
use App\Managers\DeedFriendManager;
use App\Services\Deed\FriendService;
use Illuminate\Http\Request;

class FriendController extends Controller
{
    public function overview()
    {
        $uid = Auth::auth();

        $fs = new FriendService();
        $data = $fs->overview($uid);

        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 好友列表未读概览
     */
    public function getListCnt()
    {
        $uid = Auth::auth();

        $fs = new FriendService();
        $data = $fs->getListCnt($uid);

        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 全部好友列表
     * @param  Request  $request
     * @return array
     */
    public function getAllList(Request $request)
    {
        $uid = Auth::auth();

        $pages = array(
            'limit' => 20,
            'page' => $request->get('page', 1)
        );

        $fs = new FriendService();
        $data = $fs->getAllList($uid, $pages);

        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 相互喜欢列表
     * @param  Request  $request
     * @return array
     */
    public function getEachLikeList(Request $request)
    {
        $uid = Auth::auth();

        $pages = array(
            'limit' => 20,
            'page' => $request->get('page', 1)
        );

        $fs = new FriendService();
        $data = $fs->getEachLikeList($uid, $pages);

        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 星标好友列表
     * @param  Request  $request
     * @return array
     */
    public function getStarList(Request $request)
    {
        $uid = Auth::auth();

        $pages = array(
            'limit' => 20,
            'page' => $request->get('page', 1)
        );

        $fs = new FriendService();
        $data = $fs->getStarList($uid, $pages);

        return array(
            'code' => 200,
            'message' => 'success',
            'data' => $data
        );
    }

    /**
     * 星标某个好友
     * @param  int  $friend_uid
     * @return array
     * @deprecated DeedFriend/StarFriend
     */
    public function starFriend(int $friend_uid)
    {
        $uid = Auth::auth();

        $fs = new DeedFriendManager();
        $fs->starFriend($uid, $friend_uid);

        return array(
            'code' => 200,
            'message' => 'success'
        );
    }

    /**
     * 隐藏某个好友
     * @param  int  $friend_uid
     * @return array
     * @deprecated DeedFriend/HideFriend
     */
    public function hideFriend(int $friend_uid)
    {
        $uid = Auth::auth();

        $fs = new DeedFriendManager();
        $fs->hideFriend($uid, $friend_uid);

        return array(
            'code' => 200,
            'message' => 'success'
        );
    }


    /**
     * 聊天历史
     * @param $friend_uid
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function history($friend_uid)
    {
        $uid = Auth::auth();
        $friend_service = new FriendService();
        $data = $friend_service->history($uid, $friend_uid);
        return response([
            'code' => 200,
            'message' => 'OK',
            'data' => $data,
        ]);
    }
}
