<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdatePaymentGatewayRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->is_admin === true;
    }

    protected function prepareForValidation(): void
    {
        $this->merge([
            'status' => $this->has('status') ? $this->boolean('status') : false,
        ]);
    }

    public function rules(): array
    {
        return [
            'display_name' => 'sometimes|string|max:64',
            'status' => 'sometimes|boolean',
            'public_key' => 'nullable|string|max:5000',
            'secret_key' => 'nullable|string|max:5000',
            'webhook_secret' => 'nullable|string|max:5000',
            'location_id' => 'nullable|string|max:64',
            'environment' => ['sometimes', Rule::in(['sandbox', 'live'])],
        ];
    }
}
