#!/bin/bash
# credentials.sh - afiseaza credentialele effective pe care le va folosi `docker compose up`.
# Util cand vrei sa stii ce sa pui in Adminer fara sa ghicesti.

# Default chain: .env > shell env > docker-compose.yml defaults (= $SUBDOMAIN sau $USER).
set -a
[ -f .env ] && source .env
set +a

# Fallback urmeaza pattern-ul din docker-compose.yml: ${SUBDOMAIN:-${USER:-newsportal}}
SUB="${SUBDOMAIN:-${USER:-newsportal}}"
DB_USER="${DB_USER:-$SUB}"
DB_NAME="${DB_NAME:-$SUB}"
DB_PASSWORD="${DB_PASSWORD:-${SUB}-demo-pass-2026}"
JWT_KEY="${JWT_KEY:-${SUB}-jwt-key-2026-not-for-prod-min-32-chars-pls-replace}"

cat <<EOF
================================================================
 NewsPortal deploy credentials (pentru Adminer + alte tool-uri)
================================================================
 Linux user      : $USER
 Subdomain       : $SUB              (din \$SUBDOMAIN, fallback \$USER)

 Containers      : student-$USER-{api,db,frontend}
 Public URL      : https://$SUB.student-dev.ro

 ----- Postgres (pentru Adminer https://db.student-dev.ro) -----
 System          : PostgreSQL
 Server          : student-$USER-db
 Username        : $DB_USER
 Password        : $DB_PASSWORD
 Database        : $DB_NAME

 ----- JWT -----
 Key             : $JWT_KEY

 ----- Admin app login -----
 Email           : admin@newsportal.com
 Password        : Admin@123
 (seedat din SeedData.cs - acelasi pe orice deploy)
================================================================
EOF
