import { AUTOMATION_RUN_OUTCOMES, AUTOMATION_SCHEDULE_KINDS, } from '../automation.js';
import { ROUTE_SURFACE_KINDS, ROUTE_TARGET_KINDS, } from '../routes.js';
import { CONTROL_PLANE_CLIENT_KINDS, CONTROL_PLANE_PRINCIPAL_KINDS, CONTROL_PLANE_TRANSPORT_KINDS } from '../control-plane.js';
import { DELIVERY_KINDS } from '../deliveries.js';
import { WATCHER_SOURCE_KINDS } from '../watchers.js';
import { SURFACE_KINDS } from '../surfaces.js';
import { validateEventFields } from './shared.js';
export function validatePluginLoaded(v) {
    return validateEventFields('PLUGIN_LOADED', v, [
        { key: 'pluginName', kind: 'string' },
        { key: 'version', kind: 'string' },
        { key: 'toolCount', kind: 'number' },
    ]);
}
export function validatePluginFailed(v) {
    return validateEventFields('PLUGIN_FAILED', v, [
        { key: 'pluginName', kind: 'string' },
        { key: 'error', kind: 'string' },
    ]);
}
export function validateAutomationJobCreated(v) {
    return validateEventFields('AUTOMATION_JOB_CREATED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'name', kind: 'string' },
        { key: 'scheduleKind', kind: 'enum', values: AUTOMATION_SCHEDULE_KINDS },
        { key: 'enabled', kind: 'boolean' },
    ]);
}
export function validateAutomationJobUpdated(v) {
    return validateEventFields('AUTOMATION_JOB_UPDATED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'changedFields', kind: 'string[]' },
    ]);
}
export function validateAutomationJobEnabled(v) {
    return validateEventFields('AUTOMATION_JOB_ENABLED', v, [
        { key: 'jobId', kind: 'string' },
    ]);
}
export function validateAutomationJobDisabled(v) {
    return validateEventFields('AUTOMATION_JOB_DISABLED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'reason', kind: 'string' },
    ]);
}
export function validateAutomationRunQueued(v) {
    return validateEventFields('AUTOMATION_RUN_QUEUED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'scheduledAt', kind: 'number' },
        { key: 'forced', kind: 'boolean' },
    ]);
}
export function validateAutomationRunStarted(v) {
    return validateEventFields('AUTOMATION_RUN_STARTED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'startedAt', kind: 'number' },
        { key: 'attempt', kind: 'number' },
    ]);
}
export function validateAutomationRunCompleted(v) {
    return validateEventFields('AUTOMATION_RUN_COMPLETED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'startedAt', kind: 'number' },
        { key: 'completedAt', kind: 'number' },
        { key: 'durationMs', kind: 'number' },
        { key: 'outcome', kind: 'enum', values: AUTOMATION_RUN_OUTCOMES },
    ]);
}
export function validateAutomationRunFailed(v) {
    return validateEventFields('AUTOMATION_RUN_FAILED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'startedAt', kind: 'number' },
        { key: 'failedAt', kind: 'number' },
        { key: 'error', kind: 'string' },
        { key: 'retryable', kind: 'boolean' },
    ]);
}
export function validateAutomationRunCancelled(v) {
    return validateEventFields('AUTOMATION_RUN_CANCELLED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'cancelledAt', kind: 'number' },
        { key: 'reason', kind: 'string' },
    ]);
}
export function validateAutomationScheduleError(v) {
    return validateEventFields('AUTOMATION_SCHEDULE_ERROR', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'scheduleText', kind: 'string' },
        { key: 'error', kind: 'string' },
    ]);
}
export function validateAutomationJobAutoDisabled(v) {
    return validateEventFields('AUTOMATION_JOB_AUTO_DISABLED', v, [
        { key: 'jobId', kind: 'string' },
        { key: 'reason', kind: 'string' },
        { key: 'consecutiveFailures', kind: 'number' },
    ]);
}
export function validateRouteBindingCreated(v) {
    return validateEventFields('ROUTE_BINDING_CREATED', v, [
        { key: 'bindingId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'externalId', kind: 'string' },
        { key: 'targetKind', kind: 'enum', values: ROUTE_TARGET_KINDS },
        { key: 'targetId', kind: 'string' },
    ]);
}
export function validateRouteBindingUpdated(v) {
    return validateEventFields('ROUTE_BINDING_UPDATED', v, [
        { key: 'bindingId', kind: 'string' },
        { key: 'changedFields', kind: 'string[]' },
    ]);
}
export function validateRouteBindingResolved(v) {
    return validateEventFields('ROUTE_BINDING_RESOLVED', v, [
        { key: 'bindingId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'externalId', kind: 'string' },
        { key: 'targetKind', kind: 'enum', values: ROUTE_TARGET_KINDS },
        { key: 'targetId', kind: 'string' },
    ]);
}
export function validateRouteReplyTargetCaptured(v) {
    return validateEventFields('ROUTE_REPLY_TARGET_CAPTURED', v, [
        { key: 'bindingId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'externalId', kind: 'string' },
        { key: 'replyTargetId', kind: 'string' },
        { key: 'threadId', kind: 'string' },
    ]);
}
export function validateRouteBindingFailed(v) {
    return validateEventFields('ROUTE_BINDING_FAILED', v, [
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'externalId', kind: 'string' },
        { key: 'error', kind: 'string' },
    ]);
}
export function validateControlPlaneClientConnected(v) {
    return validateEventFields('CONTROL_PLANE_CLIENT_CONNECTED', v, [
        { key: 'clientId', kind: 'string' },
        { key: 'clientKind', kind: 'enum', values: CONTROL_PLANE_CLIENT_KINDS },
        { key: 'transport', kind: 'enum', values: CONTROL_PLANE_TRANSPORT_KINDS },
    ]);
}
export function validateControlPlaneClientDisconnected(v) {
    return validateEventFields('CONTROL_PLANE_CLIENT_DISCONNECTED', v, [
        { key: 'clientId', kind: 'string' },
        { key: 'reason', kind: 'string' },
    ]);
}
export function validateControlPlaneSubscriptionCreated(v) {
    return validateEventFields('CONTROL_PLANE_SUBSCRIPTION_CREATED', v, [
        { key: 'clientId', kind: 'string' },
        { key: 'subscriptionId', kind: 'string' },
        { key: 'topics', kind: 'string[]' },
    ]);
}
export function validateControlPlaneSubscriptionDropped(v) {
    return validateEventFields('CONTROL_PLANE_SUBSCRIPTION_DROPPED', v, [
        { key: 'clientId', kind: 'string' },
        { key: 'subscriptionId', kind: 'string' },
        { key: 'reason', kind: 'string' },
    ]);
}
export function validateControlPlaneAuthGranted(v) {
    return validateEventFields('CONTROL_PLANE_AUTH_GRANTED', v, [
        { key: 'clientId', kind: 'string' },
        { key: 'principalId', kind: 'string' },
        { key: 'principalKind', kind: 'enum', values: CONTROL_PLANE_PRINCIPAL_KINDS },
        { key: 'scopes', kind: 'string[]' },
    ]);
}
export function validateControlPlaneAuthRejected(v) {
    return validateEventFields('CONTROL_PLANE_AUTH_REJECTED', v, [
        { key: 'clientId', kind: 'string' },
        { key: 'principalId', kind: 'string' },
        { key: 'reason', kind: 'string' },
    ]);
}
export function validateDeliveryQueued(v) {
    return validateEventFields('DELIVERY_QUEUED', v, [
        { key: 'deliveryId', kind: 'string' },
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'targetId', kind: 'string' },
        { key: 'deliveryKind', kind: 'enum', values: DELIVERY_KINDS },
    ]);
}
export function validateDeliveryStarted(v) {
    return validateEventFields('DELIVERY_STARTED', v, [
        { key: 'deliveryId', kind: 'string' },
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'targetId', kind: 'string' },
        { key: 'startedAt', kind: 'number' },
    ]);
}
export function validateDeliverySucceeded(v) {
    return validateEventFields('DELIVERY_SUCCEEDED', v, [
        { key: 'deliveryId', kind: 'string' },
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'targetId', kind: 'string' },
        { key: 'completedAt', kind: 'number' },
        { key: 'durationMs', kind: 'number' },
        { key: 'statusCode', kind: 'number' },
    ]);
}
export function validateDeliveryFailed(v) {
    return validateEventFields('DELIVERY_FAILED', v, [
        { key: 'deliveryId', kind: 'string' },
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'targetId', kind: 'string' },
        { key: 'failedAt', kind: 'number' },
        { key: 'error', kind: 'string' },
        { key: 'retryable', kind: 'boolean' },
    ]);
}
export function validateDeliveryDeadLettered(v) {
    return validateEventFields('DELIVERY_DEAD_LETTERED', v, [
        { key: 'deliveryId', kind: 'string' },
        { key: 'jobId', kind: 'string' },
        { key: 'runId', kind: 'string' },
        { key: 'surfaceKind', kind: 'enum', values: ROUTE_SURFACE_KINDS },
        { key: 'targetId', kind: 'string' },
        { key: 'reason', kind: 'string' },
        { key: 'attempts', kind: 'number' },
    ]);
}
export function validateWatcherStarted(v) {
    return validateEventFields('WATCHER_STARTED', v, [
        { key: 'watcherId', kind: 'string' },
        { key: 'sourceKind', kind: 'enum', values: WATCHER_SOURCE_KINDS },
        { key: 'name', kind: 'string' },
    ]);
}
export function validateWatcherHeartbeat(v) {
    return validateEventFields('WATCHER_HEARTBEAT', v, [
        { key: 'watcherId', kind: 'string' },
        { key: 'sourceKind', kind: 'enum', values: WATCHER_SOURCE_KINDS },
        { key: 'seenAt', kind: 'number' },
        { key: 'checkpoint', kind: 'string' },
    ]);
}
export function validateWatcherCheckpointAdvanced(v) {
    return validateEventFields('WATCHER_CHECKPOINT_ADVANCED', v, [
        { key: 'watcherId', kind: 'string' },
        { key: 'sourceKind', kind: 'enum', values: WATCHER_SOURCE_KINDS },
        { key: 'checkpoint', kind: 'string' },
    ]);
}
export function validateWatcherFailed(v) {
    return validateEventFields('WATCHER_FAILED', v, [
        { key: 'watcherId', kind: 'string' },
        { key: 'sourceKind', kind: 'enum', values: WATCHER_SOURCE_KINDS },
        { key: 'error', kind: 'string' },
        { key: 'retryable', kind: 'boolean' },
    ]);
}
export function validateWatcherStopped(v) {
    return validateEventFields('WATCHER_STOPPED', v, [
        { key: 'watcherId', kind: 'string' },
        { key: 'sourceKind', kind: 'enum', values: WATCHER_SOURCE_KINDS },
        { key: 'reason', kind: 'string' },
    ]);
}
export function validateSurfaceEnabled(v) {
    return validateEventFields('SURFACE_ENABLED', v, [
        { key: 'surfaceKind', kind: 'enum', values: SURFACE_KINDS },
        { key: 'surfaceId', kind: 'string' },
        { key: 'accountId', kind: 'string' },
    ]);
}
export function validateSurfaceDisabled(v) {
    return validateEventFields('SURFACE_DISABLED', v, [
        { key: 'surfaceKind', kind: 'enum', values: SURFACE_KINDS },
        { key: 'surfaceId', kind: 'string' },
        { key: 'reason', kind: 'string' },
    ]);
}
export function validateSurfaceAccountConnected(v) {
    return validateEventFields('SURFACE_ACCOUNT_CONNECTED', v, [
        { key: 'surfaceKind', kind: 'enum', values: SURFACE_KINDS },
        { key: 'surfaceId', kind: 'string' },
        { key: 'accountId', kind: 'string' },
        { key: 'displayName', kind: 'string' },
    ]);
}
export function validateSurfaceAccountDegraded(v) {
    return validateEventFields('SURFACE_ACCOUNT_DEGRADED', v, [
        { key: 'surfaceKind', kind: 'enum', values: SURFACE_KINDS },
        { key: 'surfaceId', kind: 'string' },
        { key: 'accountId', kind: 'string' },
        { key: 'error', kind: 'string' },
    ]);
}
export function validateSurfaceCapabilityChanged(v) {
    return validateEventFields('SURFACE_CAPABILITY_CHANGED', v, [
        { key: 'surfaceKind', kind: 'enum', values: SURFACE_KINDS },
        { key: 'surfaceId', kind: 'string' },
        { key: 'capability', kind: 'string' },
        { key: 'enabled', kind: 'boolean' },
    ]);
}
