76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\CaseIntakeMode;
|
|
use App\Enums\IntakeOutcome;
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* One entry of the intake record: an incoming portal event, what the intake recognised and whether it acted. The same
|
|
* event with the same result is recorded once (fingerprint), however often the calendar is read or the mail arrives.
|
|
*/
|
|
#[Fillable(['channel_id', 'blocked_period_id', 'portal_email_id', 'booking_id', 'fingerprint', 'source', 'mode', 'outcome', 'applied', 'case_type', 'starts_on', 'ends_on', 'reference', 'reasons', 'missing', 'occurred_at'])]
|
|
class IntakeObservation extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
public const SOURCE_CALENDAR = 'calendar';
|
|
|
|
public const SOURCE_MAIL = 'mail';
|
|
|
|
public const SOURCE_ADOPTION = 'adoption';
|
|
|
|
/** A normalised channel event of a portal's interface (Architektur V2, App\Channels\Events). */
|
|
public const SOURCE_API = 'api';
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'mode' => CaseIntakeMode::class,
|
|
'outcome' => IntakeOutcome::class,
|
|
'applied' => 'boolean',
|
|
'starts_on' => 'immutable_date',
|
|
'ends_on' => 'immutable_date',
|
|
'reasons' => 'array',
|
|
'missing' => 'array',
|
|
'occurred_at' => 'immutable_datetime',
|
|
];
|
|
}
|
|
|
|
/** @return BelongsTo<Channel, $this> */
|
|
public function channel(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Channel::class);
|
|
}
|
|
|
|
/** @return BelongsTo<Booking, $this> */
|
|
public function booking(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Booking::class);
|
|
}
|
|
|
|
/** @return BelongsTo<BlockedPeriod, $this> */
|
|
public function blockedPeriod(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BlockedPeriod::class)->withTrashed();
|
|
}
|
|
|
|
public function sourceLabel(): string
|
|
{
|
|
return match ($this->source) {
|
|
self::SOURCE_MAIL => 'Portal-E-Mail',
|
|
self::SOURCE_ADOPTION => 'Bestandsübernahme',
|
|
default => 'Portalkalender',
|
|
};
|
|
}
|
|
}
|