# Load Node.js
FROM --platform=$BUILDPLATFORM node:24.12.0-bullseye-slim

# Set working directory
WORKDIR /app

# Install packages
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y python3
RUN rm -rf /var/lib/apt/lists/*

# Copy package.json
COPY ./src/package*.json ./

# Install dependencies
RUN npm ci --unsafe-perm

# Copy source
COPY ./src ./

# Create replied_ids.json
RUN touch replied_ids.json

# Create config.json
RUN cat <<EOF > /app/config.json
{
  "host": "${UWUZU_HOST}",
  "api_token": "${UWUZU_TOKEN}",
  "random_ueuse": ${TWEET_ENABLED},
  "check_interval": ${CHECK_INTERVAL},
  "rana_core_log": ${THINK_OUTPUT_ENABLED}
}
EOF

# Copy entrypoint
COPY ./entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

# Change line break
RUN sed -i 's/\r$//' /entrypoint.sh \
  && find /app -type f -exec sed -i 's/\r$//' {} \;

# Run
ENTRYPOINT ["/app/docker-entrypoint.sh"]