<?php

namespace App\Http\Requests;

use App\Enums\PriorityStatus;
use App\Enums\TodoProgress;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class TodoRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'name' => [$this->isMethod('post') ? 'required' : 'sometimes', 'string', 'max:255'],
            'status' => ['sometimes','required', Rule::enum(TodoProgress::class)],
            'description'=> ['sometimes','nullable', 'string'],
            'image' => ['sometimes', 'nullable', 'image', 'max:2048'],
            'due_date' => ['sometimes', 'nullable', 'date'],
            'priority' => ['sometimes', 'required', Rule::enum(PriorityStatus::class)],

        ];
    }

    public function messages(): array
    {
        return [
            'image.max' => "L'image ne doit pas dépasser 2 Mo.",
        ];
    }

    public function authorize(): bool
    {
        return true;
    }
}
