<?php

namespace App\Listeners;

use App\Events\EachLike;
use App\Models\NoticeModel;
use App\Models\User\UserModel;
use App\Services\User\NoticeService;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class EachLikeNotice implements ShouldQueue
{
    use InteractsWithQueue;

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

    /**
     * Handle the event.
     *
     * @param  EachLike  $event
     * @return void
     */
    public function handle(EachLike $event)
    {
        if (
            $pUser = UserModel::where('uid', $event->isLikeUid)->first()
        ) {
            $ns = new NoticeService();
            $ns->thumbMe($event->uid, $pUser->partner_id);
            NoticeModel::create([
                'uid' => $pUser->uid,
                'type' => 14,
                'title' => "收到新的心动",
                'content' => "收到1条新的心动消息",
            ]);
        }
    }
}
