<?php

namespace App\Http\Requests\Api;

use App\Enums\FuelType;
use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'postcode' => ['nullable', 'string', 'max:100'],
            'lat' => ['required_without:postcode', 'nullable', 'numeric', 'between:-90,90'],
            'lng' => ['required_without:postcode', 'nullable', 'numeric', 'between:-180,180'],
            'fuel_type' => ['required', 'string'],
            'radius' => ['nullable', 'numeric', 'between:0.1,50'],
            'sort' => ['nullable', 'string', 'in:price,distance,updated,brand,reliable'],
            'pricing_mode' => ['nullable', 'string', 'in:pump'],
        ];
    }

    public function fuelType(): FuelType
    {
        return FuelType::from(strtolower($this->string('fuel_type')->toString()));
    }

    public function radius(): float
    {
        return (float) $this->input('radius', 10.0);
    }

    public function sort(): string
    {
        return $this->input('sort', 'reliable');
    }
}
