/**
 * Server-only environment detection
 * Uses process.env.NODE_ENV (Node.js API)
 */

import type { ResourceDefinition } from '../../../platform/registry/types'

export type Environment = 'development' | 'staging' | 'production'

/**
 * Detect current environment from Node.js process.env
 * Server-only - do not import in browser code
 */
export function detectEnvironment(): Environment {
  const env = process.env.NODE_ENV || 'development'
  if (env === 'production') return 'production'
  if ((env as string) === 'staging') return 'staging'
  return 'development'
}

/**
 * Check if resource can execute in current environment
 * Production: only 'prod' resources allowed
 * Staging/Development: both 'dev' and 'prod' allowed
 *
 * Server-only - uses detectEnvironment() which accesses process.env
 */
export function canExecuteResource(resource: ResourceDefinition, environment?: Environment): boolean {
  const env = environment || detectEnvironment()
  return env === 'production' ? resource.status === 'prod' : true
}
