<?php

namespace App\Domains\Purchase\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StorePurchaseRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'status' => ['sometimes', 'string', Rule::in(['pending', 'paid', 'cancelled'])],
            'payment_status' => ['sometimes', 'string', Rule::in(['pending', 'approved', 'rejected'])],
            'payment_method' => ['nullable', 'string', 'max:255'],
            'items' => ['required', 'array', 'min:1'],
            'items.*.producto_variante_id' => ['required', 'integer', 'exists:productos_variantes,id'],
            'items.*.cantidad' => ['required', 'integer', 'min:1'],
        ];
    }
}
