<?php

namespace App\Http\Requests\SelfPaced;

use Illuminate\Foundation\Http\FormRequest;

/**
 * StorePaystackConfigRequest
 *
 * Validates Paystack configuration input (public key, secret key, webhook secret, currencies).
 *
 * Requirements: 1.2, 10.5
 */
class StorePaystackConfigRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('manage self-paced paystack');
    }

    public function rules(): array
    {
        return [
            'public_key' => ['required', 'string', 'starts_with:pk_'],
            'secret_key' => ['required', 'string', 'starts_with:sk_'],
            'webhook_secret' => ['required', 'string'],
            'currencies' => ['required', 'array', 'min:1'],
            'currencies.*' => ['required', 'string', 'in:KES,USD,GHS,NGN,ZAR'],
        ];
    }

    public function messages(): array
    {
        return [
            'public_key.starts_with' => 'Public key must start with pk_',
            'secret_key.starts_with' => 'Secret key must start with sk_',
            'currencies.min' => 'At least one currency must be selected',
        ];
    }
}
