<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class FareRule extends Model
{
    protected $fillable = ['vehicle_type_id', 'name', 'adjustment_type', 'adjustment_value', 'is_active'];

    protected function casts(): array
    {
        return [
            'adjustment_value' => 'decimal:2',
            'is_active' => 'boolean',
        ];
    }

    public function vehicleType(): BelongsTo
    {
        return $this->belongsTo(VehicleType::class);
    }

    public function apply(float $amount): float
    {
        return $this->adjustment_type === 'multiplier'
            ? round($amount * (float) $this->adjustment_value, 2)
            : round($amount + (float) $this->adjustment_value, 2);
    }
}
