# =============================================================================
# Customer Portal Backend (BFF) - Production Environment
# =============================================================================
# Copy to portal-backend.env and configure values marked with CHANGE_ME
# Variables with defaults can be omitted unless you need to override them
# =============================================================================

# -----------------------------------------------------------------------------
# REQUIRED - Must be configured (no defaults)
# -----------------------------------------------------------------------------

NODE_ENV=production
DATABASE_URL=postgresql://portal:CHANGE_ME@database:5432/portal_prod?schema=public
JWT_SECRET=CHANGE_ME_GENERATE_WITH_openssl_rand_base64_32

# -----------------------------------------------------------------------------
# Core Application
# -----------------------------------------------------------------------------

# APP_NAME=customer-portal-bff           # default
APP_BASE_URL=https://your-domain.com
# BFF_PORT=4000                          # default

# -----------------------------------------------------------------------------
# Cache & Session
# -----------------------------------------------------------------------------

REDIS_URL=redis://cache:6379/0

# -----------------------------------------------------------------------------
# Security
# -----------------------------------------------------------------------------

CORS_ORIGIN=https://your-domain.com
TRUST_PROXY=true

# CSRF Protection (generate: openssl rand -base64 32)
CSRF_SECRET_KEY=CHANGE_ME_GENERATE_WITH_openssl_rand_base64_32

# JWT (defaults shown)
# JWT_EXPIRES_IN=7d
# BCRYPT_ROUNDS=14

# Redis token handling
# AUTH_ALLOW_REDIS_TOKEN_FAILOPEN=false  # default
# AUTH_REQUIRE_REDIS_FOR_TOKENS=false    # default
# AUTH_MAINTENANCE_MODE=false            # default

# -----------------------------------------------------------------------------
# Rate Limiting (defaults shown - uncomment to override)
# -----------------------------------------------------------------------------

# RATE_LIMIT_TTL=60
# RATE_LIMIT_LIMIT=100
# AUTH_RATE_LIMIT_TTL=900
# AUTH_RATE_LIMIT_LIMIT=3
# LOGIN_RATE_LIMIT_TTL=900
# LOGIN_RATE_LIMIT_LIMIT=5

# CAPTCHA (optional)
# AUTH_CAPTCHA_PROVIDER=none             # 'none', 'turnstile', or 'hcaptcha'
# AUTH_CAPTCHA_SECRET=

# -----------------------------------------------------------------------------
# EXTERNAL SERVICES - Configure all that apply
# -----------------------------------------------------------------------------

# --- WHMCS (Billing) ---
WHMCS_BASE_URL=https://accounts.asolutions.co.jp
WHMCS_API_IDENTIFIER=CHANGE_ME
WHMCS_API_SECRET=CHANGE_ME

# WHMCS Client custom fields (IDs from WHMCS Admin → Custom Fields)
# Customer Number is typically 198; Gender and DOB are your instance-specific IDs.
WHMCS_CUSTOMER_NUMBER_FIELD_ID=198
WHMCS_GENDER_FIELD_ID=200
WHMCS_DOB_FIELD_ID=201
# WHMCS_NATIONALITY_FIELD_ID=

# Queue settings (defaults shown)
# WHMCS_QUEUE_CONCURRENCY=15
# WHMCS_QUEUE_INTERVAL_CAP=300
# WHMCS_QUEUE_TIMEOUT_MS=30000

# --- Salesforce (CRM) ---
SF_LOGIN_URL=https://asolutions.my.salesforce.com
SF_CLIENT_ID=CHANGE_ME
SF_USERNAME=CHANGE_ME
SF_PRIVATE_KEY_PATH=/app/secrets/sf-private.key

# Queue settings (defaults shown)
# SF_QUEUE_CONCURRENCY=15
# SF_QUEUE_LONG_RUNNING_CONCURRENCY=22
# SF_QUEUE_INTERVAL_CAP=600
# SF_QUEUE_TIMEOUT_MS=30000
# SF_QUEUE_LONG_RUNNING_TIMEOUT_MS=600000
# SF_DAILY_API_LIMIT=100000

# Token management (defaults shown)
# SF_AUTH_TIMEOUT_MS=30000
# SF_TOKEN_TTL_MS=720000
# SF_TOKEN_REFRESH_BUFFER_MS=60000

# Platform Events
SF_EVENTS_ENABLED=true
# SF_EVENTS_REPLAY=LATEST                # default
# SF_PUBSUB_ENDPOINT=api.pubsub.salesforce.com:7443  # default
# SF_PUBSUB_NUM_REQUESTED=25             # default
# SF_PUBSUB_QUEUE_MAX=100                # default

# --- Freebit (SIM Management) ---
FREEBIT_BASE_URL=https://i1.mvno.net/emptool/api
FREEBIT_OEM_KEY=CHANGE_ME
# FREEBIT_OEM_ID=PASI                    # default
# FREEBIT_TIMEOUT=30000                  # default
# FREEBIT_RETRY_ATTEMPTS=3               # default

# --- SFTP (SIM Call/SMS history imports) ---
# SFTP_HOST=fs.mvno.net                  # default
# SFTP_PORT=22                           # default
# SFTP_USERNAME=PASI                     # default
SFTP_PASSWORD=CHANGE_ME
# Optional but recommended (MITM protection): server host key fingerprint
# You can paste OpenSSH-style values (prefix "SHA256:" is ignored).
# SFTP_HOST_KEY_SHA256=CHANGE_ME

# --- SendGrid (Email) ---
SENDGRID_API_KEY=CHANGE_ME
# EMAIL_ENABLED=true                     # default
# EMAIL_USE_QUEUE=true                   # default
EMAIL_FROM=no-reply@asolutions.jp
# EMAIL_FROM_NAME=Assist Solutions       # default
# SENDGRID_SANDBOX=false                 # default

# -----------------------------------------------------------------------------
# Portal Configuration
# -----------------------------------------------------------------------------

PORTAL_PRICEBOOK_ID=CHANGE_ME
# PORTAL_PRICEBOOK_NAME=Portal           # default

# -----------------------------------------------------------------------------
# Logging
# -----------------------------------------------------------------------------

LOG_LEVEL=info
# PRETTY_LOGS=false                      # auto-disabled in production

# -----------------------------------------------------------------------------
# Node Runtime
# -----------------------------------------------------------------------------

NODE_OPTIONS=--max-old-space-size=512


# =============================================================================
# SALESFORCE FIELD MAPPINGS (Advanced)
# =============================================================================
# All fields have sensible defaults matching standard SF field API names.
# Only uncomment if your Salesforce org uses non-standard field names.
# =============================================================================

# --- Account Fields ---
# ACCOUNT_INTERNET_ELIGIBILITY_FIELD=Internet_Eligibility__c
# ACCOUNT_CUSTOMER_NUMBER_FIELD=SF_Account_No__c
# ACCOUNT_PORTAL_STATUS_FIELD=Portal_Status__c
# ACCOUNT_PORTAL_STATUS_SOURCE_FIELD=Portal_Registration_Source__c
# ACCOUNT_PORTAL_LAST_SIGNED_IN_FIELD=Portal_Last_SignIn__c

# --- Product Fields ---
# PRODUCT_SKU_FIELD=StockKeepingUnit
# PRODUCT_PORTAL_CATEGORY_FIELD=Product2Categories1__c
# PRODUCT_PORTAL_CATALOG_FIELD=Portal_Catalog__c
# PRODUCT_PORTAL_ACCESSIBLE_FIELD=Portal_Accessible__c
# PRODUCT_ITEM_CLASS_FIELD=Item_Class__c
# PRODUCT_BILLING_CYCLE_FIELD=Billing_Cycle__c
# PRODUCT_WHMCS_PRODUCT_ID_FIELD=WH_Product_ID__c
# PRODUCT_WHMCS_PRODUCT_NAME_FIELD=WH_Product_Name__c
# PRODUCT_INTERNET_PLAN_TIER_FIELD=Internet_Plan_Tier__c
# PRODUCT_INTERNET_OFFERING_TYPE_FIELD=Internet_Offering_Type__c
# PRODUCT_DISPLAY_ORDER_FIELD=Catalog_Order__c
# PRODUCT_SIM_DATA_SIZE_FIELD=SIM_Data_Size__c
# PRODUCT_SIM_PLAN_TYPE_FIELD=SIM_Plan_Type__c
# PRODUCT_SIM_HAS_FAMILY_DISCOUNT_FIELD=SIM_Has_Family_Discount__c
# PRODUCT_VPN_REGION_FIELD=VPN_Region__c

# --- Order Fields ---
# ORDER_TYPE_FIELD=Type
# ORDER_ACTIVATION_TYPE_FIELD=Activation_Type__c
# ORDER_ACTIVATION_SCHEDULED_AT_FIELD=Activation_Scheduled_At__c
# ORDER_ACTIVATION_STATUS_FIELD=Activation_Status__c
# ORDER_SIM_TYPE_FIELD=SIM_Type__c
# ORDER_EID_FIELD=EID__c
# ORDER_MNP_APPLICATION_FIELD=MNP_Application__c
# ORDER_MNP_RESERVATION_FIELD=MNP_Reservation_Number__c
# ORDER_MNP_EXPIRY_FIELD=MNP_Expiry_Date__c
# ORDER_MNP_PHONE_FIELD=MNP_Phone_Number__c
# ORDER_WHMCS_ORDER_ID_FIELD=WHMCS_Order_ID__c

# --- CDC Channels ---
# SF_CATALOG_PRODUCT_CDC_CHANNEL=/data/Product2ChangeEvent
# SF_CATALOG_PRICEBOOKENTRY_CDC_CHANNEL=/data/PricebookEntryChangeEvent
# SF_ORDER_CDC_CHANNEL=/data/OrderChangeEvent
# SF_ORDER_ITEM_CDC_CHANNEL=/data/OrderItemChangeEvent
