<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreateAffiliateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        // Authorization will be handled by middleware and policy
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'code' => [
                'nullable',
                'string',
                'min:3',
                'max:255',
                'regex:/^[a-zA-Z0-9_-]+$/',
            ],
            'campaign_name' => 'required|string|max:255',
            'campaign_description' => 'nullable|string|max:65535',
            'is_active' => 'nullable|boolean',
        ];
    }

    /**
     * Get custom error messages for validation rules.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'code.regex' => 'The affiliate code may only contain letters, numbers, hyphens, and underscores.',
            'code.unique' => 'This affiliate code is already in use.',
            'code.min' => 'The affiliate code must be at least 3 characters.',
            'campaign_name.required' => 'A campaign name is required.',
            'campaign_name.max' => 'The campaign name cannot exceed 255 characters.',
        ];
    }
}


