#!/bin/bash

# Script de déploiement de la Lambda PDF Converter

set -e

echo "🚀 Déploiement de la Lambda odentas-sign-pdf-converter"
echo ""

cd lambda-pdf-converter

# 1. Installation des dépendances
echo "📦 Installation des dépendances..."
npm install --production

# 2. Création du ZIP
echo "📦 Création du package ZIP..."
rm -f lambda-pdf-converter.zip
zip -r lambda-pdf-converter.zip . -x "*.git*" -x "README.md" -x "deploy.sh"

echo ""
echo "✅ Package créé: lambda-pdf-converter.zip"
echo ""
echo "📋 Prochaines étapes:"
echo ""
echo "1. Créer la Lambda dans AWS Console:"
echo "   - Nom: odentas-sign-pdf-converter"
echo "   - Runtime: Node.js 20.x"
echo "   - Mémoire: 512 MB"
echo "   - Timeout: 5 minutes"
echo ""
echo "2. Uploader le fichier lambda-pdf-converter.zip"
echo ""
echo "3. Configurer les variables d'environnement:"
echo "   CLOUDINARY_CLOUD_NAME=duecox5va"
echo "   CLOUDINARY_API_KEY=265234555873541"
echo "   CLOUDINARY_API_SECRET=DS5k0Zo2LxDkE5KmA3nFsT3bL1M"
echo "   AWS_REGION=eu-west-3"
echo "   SOURCE_BUCKET=odentas-sign"
echo "   DEST_BUCKET=odentas-docs"
echo ""
echo "4. Ajouter le trigger S3:"
echo "   - Bucket: odentas-sign"
echo "   - Event: PUT"
echo "   - Prefix: source/"
echo "   - Suffix: .pdf"
echo ""
echo "5. Ajouter les permissions IAM au rôle de la Lambda"
echo ""
