export type RuntimeType = 'nodejs18' | 'python3.9' | 'go1.20' | 'custom';

export type ExecutionStatus = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'canceled';

export type OwnerType = 'individual' | 'team';

export interface Owner {
  type: OwnerType;
  name: string;
  owner: string;
}

export interface FunctionDefinition {
  id: string;
  name: string;
  app_id: string;
  runtime: RuntimeType;
  image: string;
  handler: string;
  code?: string;
  environment?: Record<string, string>;
  timeout: string;
  memory: number;
  owner: Owner;
  created_at: string;
  updated_at: string;
}

export interface FunctionExecution {
  id: string;
  function_id: string;
  status: ExecutionStatus;
  input?: any;
  output?: any;
  error?: string;
  duration?: number;
  memory_used?: number;
  logs?: string[];
  container_id?: string;
  executor_id: string;
  created_at: string;
  started_at?: string;
  completed_at?: string;
}

export interface CreateFunctionRequest {
  name: string;
  app_id: string;
  runtime: RuntimeType;
  image: string;
  handler: string;
  code?: string;
  environment?: Record<string, string>;
  timeout: string;
  memory: number;
  owner: Owner;
}

export interface UpdateFunctionRequest {
  name?: string;
  runtime?: RuntimeType;
  image?: string;
  handler?: string;
  code?: string;
  environment?: Record<string, string>;
  timeout?: string;
  memory?: number;
  owner?: Owner;
}

export interface ExecuteFunctionRequest {
  function_id: string;
  input?: any;
  async?: boolean;
}

export interface ExecuteFunctionResponse {
  execution_id: string;
  status: ExecutionStatus;
  output?: any;
  error?: string;
  duration?: number;
  memory_used?: number;
}

export interface RuntimeInfo {
  type: RuntimeType;
  version: string;
  available: boolean;
  default_image: string;
  description: string;
}