<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class CreateOrderRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /** @return array<string, mixed> */
    public function rules(): array
    {
        return [
            'address_id' => ['required', 'exists:addresses,id', function ($attr, $value, $fail) {
                if ($this->user()->addresses()->where('id', $value)->doesntExist()) {
                    $fail(__('Invalid address.'));
                }
            }],
        ];
    }
}
