FROM python:3.12-slim

# Install dependencies for cardano-cli
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    ca-certificates \
    libsodium23 \
    libnuma1 \
    && rm -rf /var/lib/apt/lists/*

# Download and install cardano-cli
# Using the official release from cardano-node 10.4.1 (compatible with current network)
ARG CARDANO_CLI_VERSION=10.4.1
RUN curl -L "https://github.com/IntersectMBO/cardano-node/releases/download/${CARDANO_CLI_VERSION}/cardano-node-${CARDANO_CLI_VERSION}-linux.tar.gz" \
    -o /tmp/cardano-node.tar.gz && \
    mkdir -p /tmp/cardano && \
    tar -xzf /tmp/cardano-node.tar.gz -C /tmp/cardano && \
    cp /tmp/cardano/bin/cardano-cli /usr/local/bin/ && \
    chmod +x /usr/local/bin/cardano-cli && \
    rm -rf /tmp/cardano /tmp/cardano-node.tar.gz

# Verify cardano-cli installation
RUN cardano-cli --version

WORKDIR /app

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application
COPY . .

# Run with uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8765", "--workers", "2"]
