<?php

namespace Modules\Routing\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Routing\Database\Factories\RoutePricingFactory;
use Modules\Shared\Enums\VehicleOption;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;

class RoutePricing extends Model
{
    /** @use HasFactory<RoutePricingFactory> */
    use HasFactory, LogsActivity;

    /**
     * Full CRUD audit trail — pricing changes must never silently reprice
     * existing bookings (domain.md §3), so every edit here is traceable to
     * who changed it and when (T6.2).
     */
    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logFillable()
            ->logOnlyDirty()
            ->dontLogEmptyChanges()
            ->useLogName('routing');
    }

    protected $table = 'route_pricing';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'ev_route_id',
        'vehicle_option',
        'price',
        'is_blocked',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'vehicle_option' => VehicleOption::class,
            'price' => 'decimal:2',
            'is_blocked' => 'boolean',
        ];
    }

    public function route(): BelongsTo
    {
        return $this->belongsTo(EvRoute::class, 'ev_route_id');
    }
}
