<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class UpdateEmpletteAdminRequest extends FormRequest
{
    public function authorize(): bool
    {
        $user = $this->user();

        return $user !== null && $user->isAdmin();
    }

    /** @return array<string, mixed> */
    public function rules(): array
    {
        return [
            'items' => ['required', 'array', 'min:1'],
            'items.*.id' => ['nullable', 'integer', 'exists:emplette_items,id'],
            'items.*.name' => ['required', 'string', 'max:255'],
            'items.*.quantity' => ['nullable', 'integer', 'min:1'],
            'items.*.client_price' => ['required', 'numeric', 'min:0'],
            'items.*.admin_price' => ['required', 'numeric', 'min:0'],
            // Note interne / message destiné au client (admin)
            'admin_notes' => ['nullable', 'string', 'max:1000'],
            // Compat : ancien champ
            'notes' => ['nullable', 'string', 'max:1000'],
            'status' => ['nullable', 'string', 'in:quoting,quoted,client_review,accepted,rejected'],
        ];
    }
}

