<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class DealBuilderDeliverySettingsRequest extends FormRequest
{
    public function authorize(): bool
    {
        return Auth::check();
    }

    public function rules(): array
    {
        return [
            'allow_home_delivery' => [
                'boolean',
            ],
            'max_delivery_distance' => [
                'nullable',
                'numeric',
                'min:0',
            ],
            'locations' => 'array',
            'locations.*.id' => 'nullable|integer',
            'locations.*.name' => 'required|string|max:255',
            'locations.*.address1' => 'nullable|string|max:255',
            'locations.*.address2' => 'nullable|string|max:255',
            'locations.*.city' => 'nullable|string|max:255',
            'locations.*.county' => 'nullable|string|max:255',
            'locations.*.postcode' => 'nullable|string|max:255',
            'locations.*.fee' => 'required|numeric|min:0',
            'locations.*.active' => 'boolean',
            'price_tiers' => 'array',
            'price_tiers.*.from_miles' => 'required|numeric|min:0',
            'price_tiers.*.to_miles' => 'required|numeric|min:0',
            'price_tiers.*.fee' => 'required|numeric|min:0',
        ];
    }
}
