# OMNL Bank online — nginx reverse proxy (Central Bank style production)
# TLS: mount certs at deploy/nginx/certs/fullchain.pem + privkey.pem

upstream omnl_api {
    server token-aggregation:3000;
}

upstream omnl_settlement {
    server settlement-middleware:3011;
}

upstream omnl_exchange {
    server dbis-exchange:3012;
}

upstream omnl_frontend {
    server frontend:80;
}

server {
    listen 80;
    server_name bank.omnl.hybxfinance.io localhost;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name bank.omnl.hybxfinance.io localhost;

    ssl_certificate     /etc/nginx/certs/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;

    add_header X-OMNL-Bank "online" always;
    add_header X-OMNL-Chains "128" always;

    # Frontend — Central Bank / Office 24 / DBIS Trade
    location / {
        proxy_pass http://omnl_frontend;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    # OMNL API (token-aggregation)
    location /api/v1/ {
        proxy_pass http://omnl_api/api/v1/;
        proxy_set_header Host $host;
        proxy_read_timeout 120s;
    }

    # Settlement middleware
    location /settlement/ {
        proxy_pass http://omnl_settlement/api/v1/settlement/;
        proxy_set_header Host $host;
        proxy_set_header Authorization $http_authorization;
        proxy_read_timeout 120s;
    }

    # DBIS Exchange
    location /exchange/ {
        proxy_pass http://omnl_exchange/api/v1/exchange/;
        proxy_set_header Host $host;
        proxy_read_timeout 120s;
    }

    location /health {
        return 200 'OMNL Bank online — 128 chains';
        add_header Content-Type text/plain;
    }
}
