<?php

namespace App\Http\Requests\API;

use Illuminate\Foundation\Http\FormRequest;

class StoreOrderRequest extends FormRequest
{
    public function authorize(): bool { return auth()->check(); }

    public function rules(): array
    {
        return [
            'items'                      => ['required', 'array', 'min:1'],
            'items.*.product_id'         => ['required', 'integer', 'exists:products,id'],
            'items.*.quantity'           => ['required', 'integer', 'min:1'],
            'shipping_address'           => ['required', 'array'],
            'shipping_address.name'      => ['required', 'string'],
            'shipping_address.address'   => ['required', 'string'],
            'shipping_address.city'      => ['required', 'string'],
            'shipping_address.zip'       => ['required', 'string'],
            'shipping_address.country'   => ['required', 'string'],
            'payment_method'             => ['nullable', 'string'],
        ];
    }
}
