74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* A message read from the landlord's mailbox (v0.11, S2/S3), stored before anything is done with it. It is assigned
|
|
* to a case only by a reliable reference (CH-13); otherwise it waits in the inbox for the landlord. Being assigned is
|
|
* not yet permission to take anything over.
|
|
*/
|
|
#[Fillable(['mailbox_id', 'message_id', 'medium', 'intent', 'decision', 'in_reply_to', 'references', 'from_address', 'from_name', 'to_addresses', 'subject', 'body', 'received_at', 'test_mode', 'status', 'booking_id', 'match_reason', 'hints', 'portal_email_id', 'extraction_status', 'extraction', 'processed_at'])]
|
|
class InboundMessage extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
public const NEW = 'new';
|
|
|
|
/** Assigned to a case by a reliable reference. */
|
|
public const ASSIGNED = 'assigned';
|
|
|
|
/** Waits for the landlord: no or no reliable reference, or contradicting hints. */
|
|
public const NEEDS_REVIEW = 'needs_review';
|
|
|
|
/** A portal notification, handled by the existing portal path. */
|
|
public const PORTAL = 'portal';
|
|
|
|
public const IGNORED = 'ignored';
|
|
|
|
/** Done: details taken over or decided by the landlord. */
|
|
public const PROCESSED = 'processed';
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'body' => 'encrypted',
|
|
'references' => 'array',
|
|
'to_addresses' => 'array',
|
|
'hints' => 'array',
|
|
'extraction' => 'array',
|
|
'decision' => 'array',
|
|
'test_mode' => 'boolean',
|
|
'received_at' => 'immutable_datetime',
|
|
'processed_at' => 'immutable_datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Booking, $this>
|
|
*/
|
|
public function booking(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Booking::class);
|
|
}
|
|
|
|
public function statusLabel(): string
|
|
{
|
|
return match ($this->status) {
|
|
self::ASSIGNED => 'einem Vorgang zugeordnet',
|
|
self::NEEDS_REVIEW => 'zu klären',
|
|
self::PORTAL => 'Portal-Mail',
|
|
self::IGNORED => 'ignoriert',
|
|
self::PROCESSED => 'erledigt',
|
|
default => 'neu',
|
|
};
|
|
}
|
|
}
|