<?php

namespace App\Services\User\Notifications;

use App\Services\NoticeService\Channels\TemplateChannel;
use App\Services\NoticeService\Notification;

class OldUserToOncePairNotification extends Notification
{


    protected $title = "老用户召回-仅参与过一次活动的用户";


    public function __construct($to_uid)
    {
        parent::__construct($to_uid);
    }


    /**
     * 是否订阅
     * @return bool
     */
    public function subscribe(): bool
    {
        return true;
    }


    /**
     * 节流阀
     * @return bool
     */
    public function throttle(): bool
    {
        if (
            \DB::connection('mysql_datalog')
            ->table("notice_logs")
            ->where('title', $this->title)
            ->where('uid', $this->to_uid)
            ->first()
        ) {
            return false;
        }

        return true;
    }


    /**
     * 通知渠道
     * @return array
     */
    public function via(): array
    {
        return [
            $this->toTemplate(),
        ];
    }

    /**
     * 模版消息
     * @return TemplateChannel
     */
    public function toTemplate()
    {
        $templates = [
            [
                'template_id' => '5XGwNkYJuNWaWn0-GN_ROw8uVyOgJrvfdBwd8aq-wFw',
                'data' => [
                    'first' => [
                        'value' => "送你一张“72小时恋爱体验”报名券，报名可立即生效，直升最高匹配成功率\n",
                    ],
                    'keyword1' => [
                        'value' => "领取免费券",
                    ],
                    'keyword2' => [
                        'value' => "脱单告急",
                    ],
                    'keyword3' => [
                        'value' => date('Y-m-d'),
                    ],
                    'keyword4' => [
                        'value' => "72小时恋爱体验",
                    ],
                    'remark' => [
                        'value' => "\n经过不断的优化改进，小象将会为你匹配更精准的ta，带来更好的活动体验！快来，别让属于你的ta等太久~",
                    ],
                ],
            ],
            [
                'template_id' => 'ugxHaIxl5sFf2T00QZdCc0l4qELRUfEtw1HnCE7PDww',
                'data' => [
                    'first' => [
                        'value' => "送你一张“72小时恋爱体验”报名券，报名可立即生效，直升最高匹配成功率\n",
                    ],
                    'keyword1' => [
                        'value' => "领取免费券",
                    ],
                    'keyword2' => [
                        'value' => "脱单告急",
                    ],
                    'keyword3' => [
                        'value' => "72小时恋爱体验",
                    ],
                    'keyword4' => [
                        'value' => date('Y-m-d'),
                    ],
                    'remark' => [
                        'value' => "\n经过不断的优化改进，小象将会为你匹配更精准的ta，带来更好的活动体验！快来，别让属于你的ta等太久~",
                    ],
                ],
            ],
        ];

        $rand = rand(0, count($templates) - 1);
        $templateId = $templates[$rand]['template_id'];
        $data = $templates[$rand]['data'];

        return new TemplateChannel($this->to_uid, $templateId, $data);
    }

    /**
     * 跳转地址
     * @return string
     */
    protected function getPagePath()
    {
        return "fpdx/pages/starter/starter";
    }
}
