<?php

namespace App\Services\Partner\Notifications;

use App\Models\User\UserModel;
use App\Services\NoticeService\Channels\MiniTemplateChannel;
use App\Services\NoticeService\Channels\TemplateChannel;
use App\Services\NoticeService\Notification;

class RecommendNotChangeNotification extends Notification
{

    protected $title = "交友卡片-卡片取消推荐未更换通知";


    private $user;


    public function __construct($to_uid)
    {
        parent::__construct($to_uid);
        $this->user = UserModel::select('nickname', 'sex')->find($to_uid);
    }


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

    /**
     * 节流阀
     * @return bool
     */
    public function throttle(): bool
    {
        return true;
    }


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


    protected function getPagePath()
    {
        return "pages/my-friend-card-editor/my-friend-card-editor";
    }


    /**
     * 模版消息
     * @return TemplateChannel
     */
    public function toTemplate()
    {
        $number = rand(101, 249);
        $name = $this->user->sex == 2 ? "小哥哥" : "小姐姐";
        $templates = [
            [
                'template_id' => 'JVICUmaP38MoputCdKVn5AAIFmc7ZO9eewj2FyW58NM',
                'data' => [
                    'first' => [
                        'value' => "昨日有{$number}个{$name}，访问了你的个人主页",
                    ],
                    'keyword1' => [
                        'value' => '暂时未收到心动，建议你更换照片哦~',
                    ],
                    'keyword2' => [
                        'value' => "一张精致清晰的照片能够迅速吸引异性的注意力！",
                    ],
                    'remark' => [
                        'value' => "点此更换个人照片，有助于你收到更多心动，快速脱单~",
                    ],
                ]
            ],
            [
                'template_id' => 'vj03Lys62tcWH0BAx2bKdDbzxBnhwe4Fhs3GXqbxkTg',
                'data' => [
                    'first' => [
                        'value' => "昨日有{$number}个{$name}，访问了你的个人主页",
                    ],
                    'keyword1' => [
                        'value' => "暂时未收到心动，建议你更换照片哦~",
                    ],
                    'keyword2' => [
                        'value' => "一张精致清晰的照片能够迅速吸引异性的注意力！",
                    ],
                    'remark' => [
                        'value' => "点此更换个人照片，有助于你收到更多心动，快速脱单~",
                    ],
                ]
            ],
            [
                'template_id' => 'hHzk7eaLtmNBdhsZwfgQur83_xAWvMs1t1_5fLaNwbc',
                'data' => [
                    'first' => [
                        'value' => "昨日有{$number}个{$name}，访问了你的个人主页",
                    ],
                    'keyword1' => [
                        'value' => "暂时未收到心动，建议你更换照片哦~",
                    ],
                    'keyword2' => [
                        'value' => "一张精致清晰的照片能够迅速吸引异性的注意力！",
                    ],
                    'keyword3' => [
                        'value' => "昨日",
                    ],
                    'remark' => [
                        'value' => "点此更换个人照片，有助于你收到更多心动，快速脱单~",
                    ],
                ]
            ],
        ];
        $rand = rand(0, count($templates) - 1);
        $templateId = $templates[$rand]['template_id'];
        $data = $templates[$rand]['data'];
        return new TemplateChannel($this->to_uid, $templateId, $data);
    }


    /**
     * 小程序模版消息
     * @return MiniTemplateChannel
     */
    public function toMiniTemplate()
    {
        $number = rand(1000, 10000);
        $name = $this->user->sex == 2 ? "小哥哥" : "小姐姐";
        $templates = [
            [
                'template_id' => 'ClWa4GHeJSh0_u8jsi6zWzvskIU7LvMbig8bkhHoehw',
                'data' => [
                    'keyword1' => [
                        'value' => "昨日有{$number}个{$name}，访问了你的个人主页"
                    ],
                    'keyword2' => [
                        'value' => "暂时未收到心动，建议你更换照片哦~"
                    ],
                    'keyword3' => [
                        'value' => "一张精致清晰的照片能够迅速吸引异性的注意力！\n点此更换个人照片，有助于你收到更多心动，快速脱单~",
                    ],
                ]
            ],
            [
                'template_id' => 'Xcp8AnnJr-cJmDMcr9WyIQmKgpN4qu6q6lStS0ZAiqs',
                'data' => [
                    'keyword1' => [
                        'value' => "昨日有{$number}个{$name}，访问了你的个人主页"
                    ],
                    'keyword2' => [
                        'value' => "暂时未收到心动，建议你更换照片哦~"
                    ],
                    'keyword3' => [
                        'value' => "一张精致清晰的照片能够迅速吸引异性的注意力！\n点此更换个人照片，有助于你收到更多心动，快速脱单~",
                    ],
                ]
            ],
            [
                'template_id' => 'dyXPTYwXRTywADyfFcxuUVckNeIldrieTbZtFfc9oHI',
                'data' => [
                    'keyword1' => [
                        'value' => "昨日有{$number}个{$name}，访问了你的个人主页"
                    ],
                    'keyword2' => [
                        'value' => $this->user->nickname,
                    ],
                    'keyword3' => [
                        'value' => "暂时未收到心动，建议你更换照片哦~"
                    ],
                    'keyword4' => [
                        'value' => "一张精致清晰的照片能够迅速吸引异性的注意力！\n点此更换个人照片，有助于你收到更多心动，快速脱单~",
                    ],
                ]
            ],
        ];
        $rand = rand(0, count($templates) - 1);
        $templateId = $templates[$rand]['template_id'];
        $data = $templates[$rand]['data'];
        return new MiniTemplateChannel($this->to_uid, $templateId, $data);
    }
}
