<?php

namespace App\Services\Partner;

use App\Models\NoticeModel;
use App\Models\PartnerModel;
use App\Models\User\UserModel;
use App\Models\Log\PartnerCheckNoticeModel;
use PocketBE\MsyPush\Jobs\RegistEventJob;

class NoticeService
{

    /**
     * 认证成功
     * @param int $to_uid
     * @return mixed
     */
    public function authenticationSuccess($to_uid)
    {
        $title = "交友卡片-身份认证成功";
        $user = UserModel::find($to_uid);
        $partner = PartnerModel::find($user->partner_id);
        $payload = [
            'to_user' => $user->getAuth(),
            'card' => $partner->toArray(),
        ];
        dispatch(new RegistEventJob(10201, $payload))->onQueue("{push}");
    }


    /**
     * 照片审核成功
     * @param int $to_uid
     * @return mixed
     */
    public function checkPartnerSuccess($to_uid)
    {
        $title = "交友卡片-照片审核成功";
        $user = UserModel::find($to_uid);
        $partner = PartnerModel::find($user->partner_id);
        $payload = [
            'to_user' => $user->getAuth(),
            'card' => $partner->toArray(),
        ];
        dispatch(new RegistEventJob(10202, $payload))->onQueue("{push}");
    }


    /**
     * 语音审核成功
     * @param int $to_uid
     * @return mixed
     */
    public function checkVoiceSuccess($to_uid)
    {
        $title = "交友卡片-语音审核成功";
        $user = UserModel::find($to_uid);
        $partner = PartnerModel::find($user->partner_id);
        $payload = [
            'to_user' => $user->getAuth(),
            'card' => $partner->toArray(),
        ];
        dispatch(new RegistEventJob(10203, $payload))->onQueue("{push}");
    }


    /**
     * 卡片审核失败
     * @param int $to_uid
     * @return mixed
     */
    public function checkPartnerFail($to_uid)
    {
        $title = "交友卡片-照片审核失败";
        $user = UserModel::find($to_uid);
        $partner = PartnerModel::find($user->partner_id);
        $payload = [
            'to_user' => $user->getAuth(),
            'card' => $partner->toArray(),
        ];
        dispatch(new RegistEventJob(10204, $payload))->onQueue("{push}");
    }


    /**
     * 语音审核失败
     * @param int $to_uid
     * @return void
     */
    public function checkVoiceFail($to_uid)
    {
        $user = UserModel::find($to_uid);
        $partner = PartnerModel::find($user->partner_id);
        $payload = [
            'to_user' => $user->getAuth(),
            'card' => $partner->toArray(),
        ];
        dispatch(new RegistEventJob(10205, $payload))->onQueue("{push}");
    }


    /**
     * 交友卡片-上架通知
     * @param int $to_uid
     * @return void
     */
    public function partnerSell($to_uid)
    {
        $title = "交友卡片-上架成功";
        // 系统通知
        NoticeModel::create([
            'uid' => $to_uid,
            'title' => '交友卡片审核通过',
            'content' => "你好，你的交友卡片已审核通过，现在已经将有趣的你推荐到交友大厅了哦~",
            'type' => 5
        ]);

        $user = UserModel::find($to_uid);
        $partner = PartnerModel::find($user->partner_id);
        $payload = [
            'to_user' => $user->getAuth(),
            'card' => $partner->toArray(),
        ];
        dispatch(new RegistEventJob(10206, $payload))->onQueue("{push}");
    }


    public function partnerCheckLog($uid, $partner_id, $field, $check, $new)
    {
        $log = PartnerCheckNoticeModel::create([
            'uid' => $uid,
            'partner_id' => $partner_id,
            'field' => $field,
            'check' => $check,
            'new' => $new
        ]);
        return $log;
    }


    /**
     * 交友卡片-卡片取消推荐通知
     * @param int $to_uid
     */
    public function recommendCancel($to_uid)
    {
        $title = "交友卡片-卡片取消推荐通知";
        NoticeModel::create([
            'uid' => $to_uid,
            'title' => '这样的照片能迅速吸引异性的目光！',
            'content' => "教你如何拍一张精致的照片，上传到你的交友卡片，一定会收到来自异性更多的心动！！",
            'type' => 5,
            'type_id' => 0,
            'tab_content' => '查看教学',
            'tab_url' => "https://mp.weixin.qq.com/s/Jsk1GRiVyE872PWM7XkAFQ",
        ]);

        $user = UserModel::find($to_uid);
        $payload = [
            'to_user' => $user->getAuth(),
            'user' => $user->toArray(),
            'meta' => [
                'number' => rand(1000, 2499),
                'call' => ($user->sex == 2) ? "小哥哥" : "小姐姐",
            ]
        ];
        dispatch(new RegistEventJob(10207, $payload))->onQueue("{push}");
    }


    public function recommendCancelNotChange($to_uid)
    {
        $title = "交友卡片-卡片取消推荐未更换通知";

        $notification = new \App\Services\Partner\Notifications\RecommendNotChangeNotification($to_uid);
        $notification->send();
    }
}
