export type DevToolActionGroupDto =
    | "deploy"
    | "database"
    | "remote-api"
    | "remote-front"
    | "local-api"
    | "local-front"

export type DevToolPageDto =
    | "build"
    | "deploy"
    | "releases"
    | "database"
    | "runtime"
    | "profiles"
    | "release"

export interface DevToolBuildProjectDto {
    key: string
    label: string
    status: "missing" | "ready"
    artifactsPath: string | null
    sourcePath: string | null
    note: string | null
}

export type DevToolBuildChannelDto = "api" | "front"

export interface DevToolBuildChannelSummaryDto {
    channel: DevToolBuildChannelDto
    label: string
    requestedReleaseName: string | null
    releaseName: string | null
    releaseSelected: boolean
    buildManifestAvailable: boolean
    artifactsDirectory: string | null
    buildManifestPath: string | null
    builtAt: string | null
    projects: DevToolBuildProjectDto[]
    note: string | null
}

export interface DevToolBuildSummaryDto {
    requestedReleaseName: string | null
    releaseName: string | null
    releaseSelected: boolean
    buildManifestAvailable: boolean
    artifactsDirectory: string | null
    buildManifestPath: string | null
    builtAt: string | null
    projects: DevToolBuildProjectDto[]
    note: string | null
    simplifiedMode: boolean
    api: DevToolBuildChannelSummaryDto
    front: DevToolBuildChannelSummaryDto
}

export type DevToolProfileConfigLayerDto = "base" | "local-override"

export type DevToolTaskStatusDto = "queued" | "running" | "succeeded" | "failed"

export type DevToolProcessStatusDto =
    | "running"
    | "stopped"
    | "degraded"
    | "unknown"
    | "untracked"
    | "not-configured"
    | "self"

export type DevToolProcessActivityDto =
    | "idle"
    | "checking"
    | "starting"
    | "stopping"
    | "restarting"

export type DevToolProcessPresentationDto =
    | "runtime-service"
    | "static-site"

export type DevToolPublicReachabilityStatusDto =
    | "reachable"
    | "unreachable"
    | "untested"

export type DevToolPublicReachabilityDetailDto =
    | "http-ok"
    | "http-error"
    | "timeout"
    | "network-error"

export type DevToolTerminalTargetDto = "local-front" | "local-api"

export type DevToolTerminalSessionStatusDto = "open" | "closed"

export interface DevToolActionSupportDto {
    releaseName: boolean
    projectKeys: boolean
    skipVerify: boolean
    skipInstall: boolean
    skipMigration: boolean
    confirmDangerous: boolean
}

export interface DevToolActionDto {
    id: string
    label: string
    description: string
    group: DevToolActionGroupDto
    page: DevToolPageDto
    available: boolean
    dangerous: boolean
    running: boolean
    note: string | null
    supports: DevToolActionSupportDto
}

export interface DevToolTaskDto {
    id: string
    actionId: string
    label: string
    contextKey: string | null
    triggeredByTaskId: string | null
    triggeredByActionId: string | null
    followUpActionId: string | null
    followUpTaskId: string | null
    status: DevToolTaskStatusDto
    startedAt: string
    finishedAt: string | null
    lastOutputAt: string | null
    lastHeartbeatAt: string | null
    exitCode: number | null
    currentPhase: string | null
    stdout: string
    stderr: string
    summary: string | null
}

export type DevToolProcessLogsModeDto = "snapshot" | "append" | "reset"

export interface DevToolPublicReachabilityDto {
    url: string | null
    status: DevToolPublicReachabilityStatusDto
    detail: DevToolPublicReachabilityDetailDto | null
    httpStatus: number | null
    checkedAt: string | null
}

export interface DevToolProcessUrlCheckDto {
    key: string
    label: string
    url: string
    kind: "direct" | "public"
    reachability: DevToolPublicReachabilityDto
    note: string | null
}

export interface DevToolProcessDto {
    key: string
    label: string
    group: DevToolActionGroupDto
    status: DevToolProcessStatusDto
    activity: DevToolProcessActivityDto
    presentation: DevToolProcessPresentationDto
    pid: number | null
    startedAt: string | null
    cwd: string | null
    logFilePath: string | null
    url: string | null
    configured: boolean
    tracked: boolean
    manageable: boolean
    reachable: boolean | null
    statusLabel: string
    statusReason: string | null
    lastCheckAt: string | null
    statusActionId: string | null
    startActionId: string | null
    stopActionId: string | null
    restartActionId: string | null
    installActionId: string | null
    terminalSupported: boolean
    terminalSessionId: string | null
    terminalSessionStatus: DevToolTerminalSessionStatusDto | null
    publicReachability: DevToolPublicReachabilityDto | null
    urlChecks: DevToolProcessUrlCheckDto[]
    note: string | null
}

export interface DevToolProcessLogsDto {
    processKey: string
    contextKey?: string | null
    lines: number
    mode: DevToolProcessLogsModeDto
    content: string
    cursor: number
    resetRequired: boolean
    truncated: boolean
    updatedAt: string | null
}

export interface DevToolDeploySummaryDto {
    remoteCurrentReleaseName: string | null
    remotePreviousReleaseName: string | null
    remoteCurrentPath: string | null
    remoteActiveReleasePath: string | null
    channelActivationConfigured: boolean
    remoteApiCurrentReleaseName: string | null
    remoteApiPreviousReleaseName: string | null
    remoteApiCurrentPath: string | null
    remoteApiActiveReleasePath: string | null
    remoteApiRollbackAvailable: boolean
    remoteFrontCurrentReleaseName: string | null
    remoteFrontPreviousReleaseName: string | null
    remoteFrontCurrentPath: string | null
    remoteFrontActiveReleasePath: string | null
    remoteFrontRollbackAvailable: boolean
    localLastReleaseName: string | null
    localLastActivatedReleaseName: string | null
    rollbackAvailable: boolean
    rawStatusJson: string | null
    note: string | null
}

export interface DevToolDeployPublicUrlsDto {
    api: string | null
    front: string | null
    socket: string | null
    releaseApiTemplate: string | null
    releaseFrontTemplate: string | null
    releaseSocketTemplate: string | null
}

export interface DevToolDeployProfileItemDto {
    name: string
    active: boolean
    selected: boolean
    remoteHost: string | null
    releaseRoot: string | null
    currentPath: string | null
    apiCurrentPath: string | null
    frontCurrentPath: string | null
    channelActivationConfigured: boolean
    apiMode: "docker" | "host" | null
    apiTarget: string | null
    frontMode: "docker" | "host" | null
    frontTarget: string | null
    databaseMode: "docker" | "host" | null
    databaseName: string | null
    publicUrls: DevToolDeployPublicUrlsDto | null
    apiBuildStrategy: string | null
    apiPrepareStrategy: string | null
    frontBuildStrategy: string | null
    frontPrepareStrategy: string | null
    smokeTestsCount: number
}

export interface DevToolDeployProfileSummaryDto {
    configPath: string | null
    localOverridePath: string | null
    localOverrideLoaded: boolean
    activeProfileName: string | null
    selectedProfileName: string | null
    envOverrideProfileName: string | null
    switchWritesTo: "base" | "local-override"
    switchAffectsRuntimeImmediately: boolean
    profiles: DevToolDeployProfileItemDto[]
    note: string | null
}

export interface DevToolDeployProfileEditorSectionsDto {
    sshJson: string
    indexatorJson: string
    remoteJson: string
    servicesJson: string
    publicUrlsJson: string
    releaseRuntimeJson: string
    databaseJson: string
    transferJson: string
    releasesJson: string
    projectsJson: string
    smokeTestsJson: string
}

export interface DevToolDeployProfileEditorDto {
    requestedProfileName: string | null
    profileName: string
    layer: DevToolProfileConfigLayerDto
    availableLayers: DevToolProfileConfigLayerDto[]
    availableProfiles: string[]
    isDefaultProfile: boolean
    isNewProfile: boolean
    seedProfileName: string | null
    existsInLayer: boolean
    configPath: string | null
    localOverridePath: string | null
    activeProfileName: string | null
    selectedProfileName: string | null
    summary: DevToolDeployProfileItemDto | null
    sections: DevToolDeployProfileEditorSectionsDto
    effectiveSections: DevToolDeployProfileEditorSectionsDto
    note: string | null
}

export interface DevToolSelectedReleaseProjectDto {
    key: string
    add: number | null
    update: number | null
    delete: number | null
    buildStrategy: string | null
    prepareStrategy: string | null
}

export type DevToolRuntimeScopeDto = "current" | "release"

export interface DevToolRuntimeTargetSummaryDto {
    scope: DevToolRuntimeScopeDto
    requestedReleaseName: string | null
    releaseName: string | null
    isolated: boolean
    configured: boolean
    apiPublicUrl: string | null
    frontPublicUrl: string | null
    socketPublicUrl: string | null
    databaseName: string | null
    workingDirectory: string | null
    note: string | null
}

export interface DevToolReleasePreviewSummaryDto {
    state: "unsupported" | "unconfigured" | "disabled" | "missing-release" | "missing-artifacts" | "ready"
    configured: boolean
    enabled: boolean
    baseDomain: string | null
    releaseName: string | null
    serverName: string | null
    publicUrl: string | null
    siteName: string | null
    configPath: string | null
    documentRoot: string | null
    topology: "same-origin" | "split-domain" | null
    apiTarget: string | null
    plannedFrontPublicUrl: string | null
    plannedApiPublicUrl: string | null
    plannedSocketPublicUrl: string | null
    installActionAvailable: boolean
    note: string | null
}

export type DevToolSelectedReleaseResolutionSourceDto = "requested" | "remote-current" | "local-last" | "none"

export type DevToolPromotionContextStatusDto = "split-build" | "aligned-build" | "remote-only" | "unresolved"

export interface DevToolPromotionContextSummaryDto {
    status: DevToolPromotionContextStatusDto
    buildReleasesSeparated: boolean
    buildApiReleaseName: string | null
    buildFrontReleaseName: string | null
    combinedBuildReleaseName: string | null
    remoteRequestedReleaseName: string | null
    remoteResolvedReleaseName: string | null
    remoteResolutionSource: DevToolSelectedReleaseResolutionSourceDto
    remoteCurrentReleaseName: string | null
    note: string | null
}

export type DevToolRemotePromotionModeDto = "mono-release" | "split-channel"

export interface DevToolRemotePromotionSummaryDto {
    mode: DevToolRemotePromotionModeDto
    requestedReleaseName: string | null
    resolvedReleaseName: string | null
    currentReleaseName: string | null
    resolutionSource: DevToolSelectedReleaseResolutionSourceDto
    buildReleasesSeparated: boolean
    channelActivationConfigured: boolean
    apiCurrentReleaseName: string | null
    frontCurrentReleaseName: string | null
    note: string | null
}

export interface DevToolSelectedReleaseSummaryDto {
    requestedReleaseName: string | null
    resolvedReleaseName: string | null
    resolutionSource: DevToolSelectedReleaseResolutionSourceDto
    exists: boolean
    manifestAvailable: boolean
    artifactsDirectory: string | null
    manifestPath: string | null
    generatedAt: string | null
    preparedAt: string | null
    dryRun: boolean | null
    skipped: boolean | null
    verified: boolean | null
    profileName: string | null
    localGitCommit: string | null
    comparisonBaseLabel: string | null
    comparisonBasePath: string | null
    remoteBuildAt: string | null
    remoteBuildTarget: string | null
    remoteBuildConfiguredBuildStrategy: string | null
    remoteBuildComposeService: string | null
    isRemoteCurrent: boolean
    isLocalLastRelease: boolean
    isLocalLastActivatedRelease: boolean
    projects: DevToolSelectedReleaseProjectDto[]
    previewSummary: DevToolReleasePreviewSummaryDto | null
    note: string | null
}

export interface DevToolDatabaseSummaryDto {
    configured: boolean
    profileName: string | null
    remoteHost: string | null
    mode: "docker" | "host" | null
    backupWriter: "host" | "container" | null
    credentialMode: "defaults-extra-file" | "inline-password" | "incomplete"
    dockerContainerName: string | null
    host: string | null
    port: number | null
    databaseName: string | null
    user: string | null
    passwordConfigured: boolean
    defaultsExtraFileConfigured: boolean
    backupDirectory: string | null
    retentionDays: number | null
    backupFlowNote: string | null
    securityNote: string | null
    note: string | null
}

export type DevToolDatabaseCloneTargetStateDto = "missing" | "empty" | "replaceable" | "problematic"

export interface DevToolDatabaseCloneTargetSummaryDto {
    state: DevToolDatabaseCloneTargetStateDto
    checkedAt: string | null
    blockingReasons: string[]
    warnings: string[]
    restorationAllowed: boolean
    preRestoreBackupRequired: boolean
    context: string[]
}

export type DevToolDatabaseCloneArtifactStatusDto = "missing" | "ready" | "ambiguous"

export interface DevToolDatabaseCloneArtifactSummaryDto {
    status: DevToolDatabaseCloneArtifactStatusDto
    releaseName: string | null
    path: string | null
    label: string | null
    note: string | null
}

export interface DevToolDatabaseCloneRestoreSummaryDto {
    restorationAllowed: boolean
    backupRequired: boolean
    backupSatisfied: boolean
    blockingReasons: string[]
}

export interface DevToolDatabaseBackupDiagnosticSummaryDto {
    status: "ok" | "warn" | "error"
    checkedAt: string | null
    errorCount: number
    warnCount: number
    headline: string | null
    remediation: string | null
}

export interface DevToolPrismaRuntimeDiagnosticSummaryDto {
    status: "ok" | "warn" | "error"
    checkedAt: string | null
    releaseName: string | null
    errorCount: number
    warnCount: number
    headline: string | null
    remediation: string | null
}

export interface DevToolApiRuntimeDiagnosticSummaryDto {
    status: "ok" | "warn" | "error"
    checkedAt: string | null
    errorCount: number
    warnCount: number
    headline: string | null
    remediation: string | null
}

export interface DevToolAppRuntimeSummaryDto {
    configured: boolean
    profileName: string | null
    remoteHost: string | null
    mode: "docker" | "host" | null
    serviceName: string
    composeService: string | null
    composeStackDir: string | null
    dockerContainerName: string | null
    hostManager: "systemd" | "pm2" | "manual" | null
    hostServiceName: string | null
    hostServiceUnitPath: string | null
    workingDirectory: string | null
    startCommand: string | null
    publicUrl: string | null
    publicSocketUrl: string | null
    releasePublicUrlTemplate: string | null
    releaseSocketUrlTemplate: string | null
    healthUrl: string | null
    healthPath: string | null
    port: number | null
    note: string | null
    bootstrapNote: string | null
}

export interface DevToolFrontStaticHostDiagnosticSummaryDto {
    status: "ok" | "warn" | "error"
    checkedAt: string | null
    errorCount: number
    warnCount: number
    headline: string | null
    remediation: string | null
}

export interface DevToolFrontApiProxyDiagnosticSummaryDto {
    status: "ok" | "warn" | "error"
    checkedAt: string | null
    errorCount: number
    warnCount: number
    headline: string | null
    remediation: string | null
}

export interface DevToolRemoteStorageDiagnosticSummaryDto {
    status: "ok" | "warn" | "error"
    checkedAt: string | null
    errorCount: number
    warnCount: number
    headline: string | null
    remediation: string | null
}

export interface DevToolReleaseLayoutDiagnosticSummaryDto {
    status: "ok" | "warn" | "error"
    checkedAt: string | null
    releaseName: string | null
    errorCount: number
    warnCount: number
    headline: string | null
    remediation: string | null
}

export interface DevToolTerminalSessionDto {
    id: string
    target: DevToolTerminalTargetDto
    processKey: string
    title: string
    status: DevToolTerminalSessionStatusDto
    pid: number | null
    cwd: string
    createdAt: string
    lastOutputAt: string | null
}

export interface DevToolTerminalBufferDto {
    sessionId: string
    processKey: string
    content: string
    truncated: boolean
    updatedAt: string | null
}

export interface DevToolsOverviewDto {
    enabled: boolean
    environment: string
    availableReleaseNames: string[]
    runtimeTargetSummary: DevToolRuntimeTargetSummaryDto | null
    buildSummary: DevToolBuildSummaryDto | null
    promotionContextSummary: DevToolPromotionContextSummaryDto | null
    remotePromotionSummary: DevToolRemotePromotionSummaryDto | null
    deploySummary: DevToolDeploySummaryDto | null
    deployProfileSummary: DevToolDeployProfileSummaryDto | null
    profileEditor: DevToolDeployProfileEditorDto | null
    selectedReleaseSummary: DevToolSelectedReleaseSummaryDto | null
    databaseSummary: DevToolDatabaseSummaryDto | null
    databaseCloneArtifactSummary: DevToolDatabaseCloneArtifactSummaryDto | null
    databaseCloneTargetSummary: DevToolDatabaseCloneTargetSummaryDto | null
    databaseCloneRestoreSummary: DevToolDatabaseCloneRestoreSummaryDto | null
    databaseBackupDiagnosticSummary: DevToolDatabaseBackupDiagnosticSummaryDto | null
    prismaRuntimeDiagnosticSummary: DevToolPrismaRuntimeDiagnosticSummaryDto | null
    appRuntimeSummary: DevToolAppRuntimeSummaryDto | null
    apiRuntimeDiagnosticSummary: DevToolApiRuntimeDiagnosticSummaryDto | null
    frontStaticHostDiagnosticSummary: DevToolFrontStaticHostDiagnosticSummaryDto | null
    frontApiProxyDiagnosticSummary: DevToolFrontApiProxyDiagnosticSummaryDto | null
    remoteStorageDiagnosticSummary: DevToolRemoteStorageDiagnosticSummaryDto | null
    releaseLayoutDiagnosticSummary: DevToolReleaseLayoutDiagnosticSummaryDto | null
    actions: DevToolActionDto[]
    tasks: DevToolTaskDto[]
    processes: DevToolProcessDto[]
}

export interface DevToolActionAcceptedDto {
    task: DevToolTaskDto
}

export interface DevToolActiveProfileAcceptedDto {
    activeProfileName: string
    selectedProfileName: string
    configPath: string
    localOverridePath: string | null
    switchedAt: string
    note: string | null
}

export interface DevToolProfileConfigSavedDto {
    profileName: string
    layer: DevToolProfileConfigLayerDto
    savedAt: string
    note: string | null
}

export interface DevToolProfileConfigDeletedDto {
    profileName: string
    layer: DevToolProfileConfigLayerDto
    deletedAt: string
    note: string | null
}

export interface DevToolTerminalSessionAcceptedDto {
    session: DevToolTerminalSessionDto
}

