<?php

namespace App\Modules\Inventory\Reservation\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use App\Modules\Inventory\Reservation\Support\ReservationEntryType;
use Illuminate\Database\Eloquent\Model;
use RuntimeException;

final class InventoryReservationMovement extends Model
{
    use BelongsToTenant;

    public const UPDATED_AT = null;

    protected $table = 'inventory_reservation_movements';

    protected $fillable = [
        'tenant_id',
        'warehouse_id',
        'item_id',
        'reservation_public_id',
        'entry_type',
        'quantity',
        'expires_at',
        'correlation_id',
        'idempotency_key',
        'idempotency_source',
        'source_type',
        'source_id',
        'actor_user_id',
        'metadata',
    ];

    protected function casts(): array
    {
        return [
            'entry_type' => ReservationEntryType::class,
            'quantity' => 'decimal:8',
            'expires_at' => 'datetime',
            'metadata' => 'array',
        ];
    }

    protected static function booted(): void
    {
        static::updating(function (): void {
            throw new RuntimeException('inventory_reservation_movements is immutable.');
        });

        static::deleting(function (): void {
            throw new RuntimeException('inventory_reservation_movements cannot be deleted.');
        });
    }
}
