<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class PushSubscriptionRequest extends FormRequest
{
    public function authorize(): bool
    {
        return Auth::check();
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        if ($this->isMethod('DELETE')) {
            return [
                'endpoint' => ['required', 'string'],
            ];
        }

        return [
            'endpoint' => ['required', 'string', 'url'],
            'publicKey' => ['required', 'string'],
            'authToken' => ['required', 'string'],
        ];
    }
}
