<?php

namespace App\Services\Violation;

use App\Models\Friends\LogModel;
use App\Models\Media\MediaSecure;
use App\Models\User\UserModel;
use PocketBE\MsyPush\Jobs\RegistEventJob;

class InvitePaint extends ViolationAbstract
{

    public function handle()
    {
        $this->user = UserModel::find($this->media->uid);
        $log = LogModel::whereRaw($this->media->field_primary)->first();
        if ($log) {
            switch ($this->media->result) {
                case MediaSecure::MANUAL_SUGGESTION_BLOCK:
                    $this->handleFailed($log);
                    break;
                case MediaSecure::MANUAL_SUGGESTION_PASS:
                    $this->handleSuccess($log);
                    break;
            }
        }
    }


    public function handleFailed($log)
    {
        $log->recall();
        $this->notification();
    }

    /**
     * 通知
     */
    public function notification()
    {
        $payload = [
            'to_user' => $this->user->getAuth(),
            'user' => $this->user->toArray(),
            'meta' => [
                'field' => '心动问答',
                'handle' => '已被删除',
            ],
        ];
        dispatch(new RegistEventJob(100016, $payload))->onQueue("{push}");
    }

    public function handleSuccess($log)
    {
    }
}
