echo "Starting 1Rx Connector Service";

source bin/activate

# SFTP Configuration
export SFTP_HOST="in-sftp.amazonsedi.com"
export SFTP_PORT=22
export SFTP_USERNAME="2HRV5XSXT0JOV"
export OUTGOING_SFTP_USERNAME="1A10E9TC5CYBE"
export SFTP_PRIVATE_KEY_PATH="/home/rxco/public_html/connector-app/keys/id_rsa_UAT"
export INCOMING_SFTP_PATH="/consultationrequests"
export OUTGOING_SFTP_PATH="/consultationresponses"

# AWS S3 Configuration
export AWS_ACCESS_KEY="AKIASJ5KUGZ3DA6YGDO2"
export AWS_SECRET_KEY="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"
export S3_BUCKET="onerx-test-bucket"
export S3_PREFIX="connector-requests"
export S3_REGION="ap-south-1"

# PGP Configuration
export PGP_PRIVATE_KEY_PATH="/home/rxco/public_html/connector-app/keys/pgp_private_key_UAT.asc"
export PGP_PUBLIC_KEY_PATH="/home/rxco/public_html/connector-app/keys/PGPPublicKey.asc"


# 1Rx API Configuration
export RX_API_BASE_URL="http://localhost:10000/api/1rx/v1"
export RX_API_KEY="amazon-6697f65c-8a8f-482e-bd27-7f4e075609d7"

# Webhook Configuration
export WEBHOOK_HOST="0.0.0.0"
export WEBHOOK_PORT=8080

# MySQL Database Configuration
export MYSQL_HOST="localhost"
export MYSQL_PORT=3306
export MYSQL_DATABASE="rx_onerx"
export MYSQL_USERNAME="rx_prafull"
export MYSQL_PASSWORD='$rBr!2DTiAWv'
export MYSQL_CHARSET="utf8mb4"
export MYSQL_POOL_SIZE=10

# Processing Configuration
export POLL_INTERVAL=3
export MAX_RETRIES=3
export RETRY_DELAY_SECONDS=300
export CLEANUP_DAYS=30

export APP_ENV=staging


# Egress: how consultation responses reach Amazon
#   api (default) = Shuttle API only, both = SFTP + Shuttle API, sftp = legacy SFTP only
export EGRESS_MODE=api

# Amazon Shuttle ConsumeConsultation API (gamma/preprod).
# Client id/secret are shared by Amazon over a secure channel; keep them out of git.
export AMAZON_PROVIDER_NAME="myrx"
export AMAZON_COGNITO_TOKEN_URL="https://shuttle-service-gamma-oauth.auth.us-west-2.amazoncognito.com/oauth2/token"
export AMAZON_CLIENT_ID=""
export AMAZON_CLIENT_SECRET=""
export AMAZON_OAUTH_SCOPE="shuttle-service-gamma-api/consultation"
export AMAZON_CONSULTATION_RESPONSE_URL="https://gamma.api.shuttle.amazon.dev/v1/consultation/response"
export AMAZON_API_TIMEOUT_SECONDS=30
export AMAZON_API_RETRY_ATTEMPTS=3
export AMAZON_API_RETRY_DELAY_SECONDS=1

# S3 bucket for prescription ZIPs handed to Amazon as pre-signed URLs.
# AWS credentials come from the boto3 default chain (instance role or
# AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY), not from this file.
export S3_BUCKET=""
export S3_REGION="ap-south-1"
export S3_PREFIX="consultation-responses"
export S3_PRESIGN_TTL_SECONDS=43200


logfile="logs/1rx-connector-service.log"
if [ -f "$logfile" ]
  then mv "$logfile" "$logfile.$(date +%H%M%S)"
fi
nohup python3.11 -m uvicorn app.main:app --workers 1 --port 8012 > logs/1rx-connector-service.log &
echo $! > temp/pid.file &

exit 0
