47 lines
927 B
PHP
47 lines
927 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\HoldStatus;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* @property HoldStatus $status
|
|
* @property Carbon $expires_at
|
|
*/
|
|
class Hold extends Model
|
|
{
|
|
protected $fillable = [
|
|
'slot_id',
|
|
'idempotency_key',
|
|
'status',
|
|
'expires_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => HoldStatus::class,
|
|
'expires_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/** @return BelongsTo<Slot, $this> */
|
|
public function slot(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Slot::class);
|
|
}
|
|
|
|
public function isExpired(): bool
|
|
{
|
|
return $this->expires_at->isPast();
|
|
}
|
|
|
|
public function isActiveHold(): bool
|
|
{
|
|
return $this->status === HoldStatus::Held && ! $this->isExpired();
|
|
}
|
|
}
|