<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Kreait\Firebase\Contract\Database;
use App\Models\User;
use App\Models\NotificationSetting;

class SendFirstPush extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:send-first-push {user_id}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public $database;
    public function __construct(Database $database)
    {
        parent::__construct(); 
        $this->database = $database;
        $this->lang = \App::getLocale();
    }
    public function handle()
    {
        //
        $user_id = $this->argument('user_id');
        $user = User::find($user_id);
        if($user && $user->is_first_push_sent == 0){
            send_notification_to_user(
                $this->database,
                $user,
                ['userId' => (string)$user->id],
                NotificationSetting::ALERT,
                'welcome_push',
                time(),
                trans('notification.home_first_alert_title', [], 'en') . "\n" . trans('notification.home_first_alert_title', [], 'ar'),
                    trans('notification.home_first_alert_body', [], 'en') . "\n" .trans('notification.home_first_alert_body', [], 'ar'),
                $user->profile_image_url
            );
            $user->is_first_push_sent = 1;
            $user->save();
        }
    }
}
