<?php

declare(strict_types=1);

namespace App\Support\WorkspaceIsolation;

use RuntimeException;

class WorkspaceIsolationViolation extends RuntimeException
{
    public static function missingTenantId(string $modelClass): self
    {
        return new self(sprintf('%s must include a managed_environment_id.', $modelClass));
    }

    public static function tenantNotFound(string $modelClass, int $tenantId): self
    {
        return new self(sprintf('%s references missing managed_environment_id %d.', $modelClass, $tenantId));
    }

    public static function tenantWorkspaceMissing(string $modelClass, int $tenantId): self
    {
        return new self(sprintf('%s managed_environment_id %d has no workspace_id mapping.', $modelClass, $tenantId));
    }

    public static function workspaceMismatch(string $modelClass, int $tenantId, int $expectedWorkspaceId, int $actualWorkspaceId): self
    {
        return new self(sprintf(
            '%s managed_environment_id %d requires workspace_id %d, received %d.',
            $modelClass,
            $tenantId,
            $expectedWorkspaceId,
            $actualWorkspaceId,
        ));
    }

    public static function tenantImmutable(string $modelClass, int $originalTenantId, int $updatedTenantId): self
    {
        return new self(sprintf(
            '%s managed_environment_id is immutable (%d -> %d).',
            $modelClass,
            $originalTenantId,
            $updatedTenantId,
        ));
    }
}
