<?php

namespace App\Listeners;

use App\Events\EachLike;
use App\Events\PairSuccess;
use App\Events\PairTwoSideAgree;
use App\Events\UnEachLike;
use App\Managers\FriendManager;
use App\Models\Friends\FriendContact;
use App\Models\Friends\FriendModel;
use App\Models\Friends\LogModel;

/**
 * 好友列表map变化监听器
 * Class FriendMapChange
 * @package App\Listeners
 */
class FriendMapChange
{

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
    }

    public function eachLike(EachLike $event)
    {
        $friendManager = new FriendManager();
        $friendManager->beContact($event->uid, $event->isLikeUid);
        $friendContact = new FriendContact();
        $friendContact->setEachLike($event->uid, $event->isLikeUid, 1);
    }

    public function unEachLike(UnEachLike $event)
    {
        $friendContact = new FriendContact();
        $friendContact->setEachLike($event->uid, $event->unLikeUid, 0);
    }

    /**
     * 分配对象活动-匹配成功
     * @param  PairSuccess  $event
     * @throws \Throwable
     */
    public function pairSuccess(PairSuccess $event)
    {
        $friendManager = new FriendManager();
        $friendManager->beContact($event->uid, $event->pairUid);
    }

    /**
     * 分配对象活动-双方同意
     * @param  PairTwoSideAgree  $event
     * @throws \Throwable
     */
    public function pairTwoSideAgree(PairTwoSideAgree $event)
    {
        $friendManager = new FriendManager();
        $friendManager->beFriend($event->uid, $event->pairUid);
    }
}
