FROM public.ecr.aws/lambda/python:3.11
# For local running:
# FROM python:3.11.10-bullseye

ARG DEV_DB_HOST
ARG DEV_DB_PORT
ARG DEV_DB_NAME


# Set working directory (Lambda task root)
WORKDIR /var/task

# Environment
ENV DB_HOST=${DEV_DB_HOST}
ENV DB_PORT=${DEV_DB_PORT}
ENV DB_NAME=${DEV_DB_NAME}

COPY backend/.env.test backend/.env

# -----------------------------
# Copy requirements FIRST (for Docker layer caching)
# -----------------------------
COPY backend/condition/handler/requirements.txt .

# Install dependencies into Lambda runtime
RUN pip install --no-cache-dir -r requirements.txt

# -----------------------------
# Copy application code
# -----------------------------
COPY utils/ utils/
COPY backend/condition/ backend/condition/

COPY backend/app/db/models/condition.py backend/app/db/models/condition.py
COPY backend/app/db/base.py backend/app/db/base.py
COPY backend/app/db/connection.py backend/app/db/connection.py
COPY backend/app/config.py backend/app/config.py

COPY backend/__init__.py backend/__init__.py
COPY backend/app/__init__.py backend/app/__init__.py
COPY backend/app/db/__init__.py backend/app/db/__init__.py


# -----------------------------
# Lambda handler
# -----------------------------
CMD ["backend/condition/handler/handler.handler"]
# For local running
# CMD ["python", "-m", "backend.condition.handler.handler"]
