import type { CosmosConfig, UpdateCosmosConfig } from './types.js';
import { productId } from '../../lib/config.js';

const CONFIG_KEY = 'cosmos-config';

// Store Cosmos config in memory for now (in production, this should be stored encrypted in Key Vault or database)
let cosmosConfig: CosmosConfig | null = null;

export async function getCosmosConfig(): Promise<CosmosConfig | null> {
  return cosmosConfig;
}

export async function updateCosmosConfig(data: UpdateCosmosConfig): Promise<CosmosConfig> {
  const config: CosmosConfig = {
    id: CONFIG_KEY,
    endpoint: data.endpoint,
    key: data.key,
    database: data.database || 'bytelyst-platform',
    updatedAt: new Date().toISOString(),
  };

  cosmosConfig = config;
  return config;
}

export async function deleteCosmosConfig(): Promise<void> {
  cosmosConfig = null;
}
