<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Minishlink\WebPush\VAPID;

class GenerateVapidKeysCommand extends Command
{
    protected $signature = 'push:vapid';

    protected $description = 'Generate a VAPID keypair for Web Push and print the .env lines.';

    public function handle(): int
    {
        $keys = VAPID::createVapidKeys();

        $this->info('VAPID keys generated. Add these to your .env:');
        $this->newLine();
        $this->line('VAPID_SUBJECT=mailto:admin@service.mir.md');
        $this->line('VAPID_PUBLIC_KEY=' . $keys['publicKey']);
        $this->line('VAPID_PRIVATE_KEY=' . $keys['privateKey']);
        $this->newLine();
        $this->warn('Keep the private key secret. Re-generating invalidates existing subscriptions.');

        return self::SUCCESS;
    }
}
