TenantAtlas/app/Support/BackupHealth/TenantBackupHealthAssessment.php
2026-04-07 23:33:38 +02:00

61 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\BackupHealth;
use App\Support\BackupQuality\BackupQualitySummary;
use Carbon\CarbonInterface;
final readonly class TenantBackupHealthAssessment
{
public const POSTURE_ABSENT = 'absent';
public const POSTURE_STALE = 'stale';
public const POSTURE_DEGRADED = 'degraded';
public const POSTURE_HEALTHY = 'healthy';
public const REASON_NO_BACKUP_BASIS = 'no_backup_basis';
public const REASON_LATEST_BACKUP_STALE = 'latest_backup_stale';
public const REASON_LATEST_BACKUP_DEGRADED = 'latest_backup_degraded';
public const REASON_SCHEDULE_FOLLOW_UP = 'schedule_follow_up';
public function __construct(
public int $tenantId,
public string $posture,
public ?string $primaryReason,
public string $headline,
public ?string $supportingMessage,
public ?int $latestRelevantBackupSetId,
public ?CarbonInterface $latestRelevantCompletedAt,
public ?BackupQualitySummary $qualitySummary,
public BackupFreshnessEvaluation $freshnessEvaluation,
public BackupScheduleFollowUpEvaluation $scheduleFollowUp,
public bool $healthyClaimAllowed,
public ?BackupHealthActionTarget $primaryActionTarget,
public string $positiveClaimBoundary,
) {}
public function hasActiveReason(): bool
{
return $this->primaryReason !== null;
}
public function tone(): string
{
return match ($this->primaryReason ?? $this->posture) {
self::REASON_NO_BACKUP_BASIS => 'danger',
self::REASON_LATEST_BACKUP_STALE => 'warning',
self::REASON_LATEST_BACKUP_DEGRADED => 'warning',
self::REASON_SCHEDULE_FOLLOW_UP => 'warning',
self::POSTURE_HEALTHY => 'success',
default => 'gray',
};
}
}