import boto3
import os
import json
from datetime import datetime
from email_service import email_service

LAMBDA_CLIENT = boto3.client('lambda')
READ_PROMOS_KACHING_ARN = os.environ['READ_PROMOS_KACHING_ARN']

def send_start_notification():
    """Send notification email using email service"""
    try:
        email_service.send_notification(
            date=datetime.now().strftime('%Y-%m-%d'),
            status='info',
            error_message=f"Promos or Kaching import process has started\n\nTime: {datetime.now().isoformat()}",
            client_email=True,
            process_name='Promos or Kaching Import'
        )
        print(f"Start notification email sent")
    except Exception as e:
        print(f"Failed to send start notification email: {str(e)}")

def lambda_handler(event, context):
    # Send start notification
    send_start_notification()
    
    payload = json.dumps(event)
    response = LAMBDA_CLIENT.invoke(
        FunctionName=READ_PROMOS_KACHING_ARN,
        InvocationType='Event',  # Asynchronous invocation
        Payload=payload
    )
    return {
        'statusCode': 202,
        'body': json.dumps({'message': 'read_promos_kaching function triggered'})
    } 