#!/bin/bash
# ═══════════════════════════════════════════════════════════════
#  clear-logs.sh — Clear mail logs and mailboxes for fresh runs
# ═══════════════════════════════════════════════════════════════
#
#  Run from the host machine (where docker-compose.yml is):
#    bash scripts/clear-logs.sh
# ═══════════════════════════════════════════════════════════════

RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'

echo ""
echo -e "${BOLD}╔══════════════════════════════════════════════════╗${NC}"
echo -e "${BOLD}║             Log & Mailbox Cleanup                ║${NC}"
echo -e "${BOLD}╚══════════════════════════════════════════════════╝${NC}"
echo ""

# Ensure we're in the project root containing docker-compose.yml
if [ ! -f "docker-compose.yml" ]; then
    echo -e "${RED}[!] Error: docker-compose.yml not found in the current directory.${NC}"
    echo -e "${RED}    Please run this script from the project root: bash scripts/clear-logs.sh${NC}"
    exit 1
fi

echo -e "${CYAN}[*] Clearing receiver-mta logs and mailbox...${NC}"
docker compose exec receiver-mta sh -c "> /var/log/mail.log; > /var/mail/bob 2>/dev/null" || echo -e "${RED}[!] Failed to clear receiver-mta cache.${NC}"

echo -e "${CYAN}[*] Clearing sender-mta logs...${NC}"
docker compose exec sender-mta sh -c "> /var/log/mail.log" || echo -e "${RED}[!] Failed to clear sender-mta cache.${NC}"

echo ""
echo -e "${GREEN}[✓] Data cleared successfully! You can now run a fresh scenario.${NC}"
echo ""
