You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cloud;
|
|
|
|
/** Immutable advisory result for starting one new public-network mutation. */
|
|
final readonly class CloudPublicNetworkMutationDecision
|
|
{
|
|
public const READY = 'ready';
|
|
public const INSTANCE_INACTIVE = 'instance_inactive';
|
|
public const SERVICE_UNAVAILABLE = 'service_unavailable';
|
|
public const MIGRATION_ACTIVE = 'migration_active';
|
|
public const BACKUP_RECOVERY_ACTIVE = 'backup_recovery_active';
|
|
public const JOB_ACTIVE = 'job_active';
|
|
public const TRANSITION_ACTIVE = 'transition_active';
|
|
public const CATALOG_UNAVAILABLE = 'catalog_unavailable';
|
|
|
|
private const CODES = [
|
|
self::READY,
|
|
self::INSTANCE_INACTIVE,
|
|
self::SERVICE_UNAVAILABLE,
|
|
self::MIGRATION_ACTIVE,
|
|
self::BACKUP_RECOVERY_ACTIVE,
|
|
self::JOB_ACTIVE,
|
|
self::TRANSITION_ACTIVE,
|
|
self::CATALOG_UNAVAILABLE,
|
|
];
|
|
|
|
/**
|
|
* @param array{id:string,kind:string,status:string,updated_at:int}|null $activeJob
|
|
*/
|
|
public function __construct(
|
|
public string $reasonCode,
|
|
public string $message,
|
|
public ?array $activeJob = null
|
|
) {
|
|
if (!in_array($reasonCode, self::CODES, true)) {
|
|
throw new \InvalidArgumentException(
|
|
'Unsupported public-network mutation admission reason'
|
|
);
|
|
}
|
|
if (($reasonCode === self::READY) !== ($message === '')) {
|
|
throw new \InvalidArgumentException(
|
|
'Public-network mutation admission message shape is invalid'
|
|
);
|
|
}
|
|
if (($reasonCode === self::JOB_ACTIVE) !== ($activeJob !== null)) {
|
|
throw new \InvalidArgumentException(
|
|
'Public-network mutation active-job shape is invalid'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function allowed(): bool
|
|
{
|
|
return $this->reasonCode === self::READY;
|
|
}
|
|
}
|