#!/bin/bash
set -e

read_secret() {
  local file="/run/secrets/$1"
  [ -f "$file" ] && cat "$file"
}

# Inject Docker secrets as ASP.NET Core environment variables
val=$(read_secret nalu_mongodb_connection);    [ -n "$val" ] && export ConnectionStrings__MongoDB="$val"
val=$(read_secret nalu_groq_api_key);          [ -n "$val" ] && export Groq__ApiKey="$val"
val=$(read_secret nalu_openrouter_api_key);    [ -n "$val" ] && export OpenRouter__ApiKey="$val"
val=$(read_secret nalu_googleai_api_key);      [ -n "$val" ] && export GoogleAi__ApiKey="$val"
val=$(read_secret nalu_stripe_secret_key);     [ -n "$val" ] && export Stripe__SecretKey="$val"
val=$(read_secret nalu_stripe_webhook_secret); [ -n "$val" ] && export Stripe__WebhookSecret="$val"
val=$(read_secret nalu_oauth_google_secret);   [ -n "$val" ] && export OAuth__Google__ClientSecret="$val"
val=$(read_secret nalu_oauth_ms_secret);       [ -n "$val" ] && export OAuth__Microsoft__ClientSecret="$val"
val=$(read_secret nalu_oauth_github_secret);   [ -n "$val" ] && export OAuth__GitHub__ClientSecret="$val"

exec dotnet Nalu.Web.dll
