<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class LogRecordsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return $this->user()->can('viewAny', \App\Models\Log::class);
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'type' => 'nullable|string|in:system,payment,mail,payment_provider,module,client,admin,php',
            'module' => 'nullable|string|max:255',
            'start_date' => 'nullable|date',
            'end_date' => 'nullable|date|after_or_equal:start_date',
            'ip_address' => 'nullable|string|max:45',
            'observer' => 'nullable|string|max:255',
            'user_id' => 'nullable|integer|min:1',
            'user_type' => 'nullable|string|in:admin,client',
            'search' => 'nullable|array',
            'search.value' => 'nullable|string|max:255',
            'draw' => 'required|integer',
            'start' => 'required|integer|min:0',
            'length' => 'required|integer|min:1|max:100',
            'order' => 'nullable|array',
            'order.*.column' => 'nullable|integer|min:0',
            'order.*.dir' => 'nullable|string|in:asc,desc',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'type.in' => 'Geçersiz log türü.',
            'end_date.after_or_equal' => 'Bitiş tarihi başlangıç tarihinden sonra olmalıdır.',
            'user_type.in' => 'Geçersiz kullanıcı türü.',
            'length.max' => 'Sayfa başına maksimum 100 kayıt gösterilebilir.',
        ];
    }
}
