#!/usr/bin/env bash
set -euo pipefail

PROJECT_ROOT="/root/kaikai_test"

cat > /etc/systemd/system/kaikai-daily-reminder.service <<'EOF'
[Unit]
Description=Kaikai Daily Report Reminder

[Service]
WorkingDirectory=/root/kaikai_test
ExecStart=/usr/bin/python3 -m daily_report.scheduled reminder
Type=oneshot
EOF

cat > /etc/systemd/system/kaikai-daily-reminder.timer <<'EOF'
[Unit]
Description=Run Kaikai Daily Report Reminder at 18:00

[Timer]
OnCalendar=*-*-* 18:00:00
Persistent=true

[Install]
WantedBy=timers.target
EOF

cat > /etc/systemd/system/kaikai-daily-reminder-followup.service <<'EOF'
[Unit]
Description=Kaikai Daily Report Follow-up Reminder

[Service]
WorkingDirectory=/root/kaikai_test
ExecStart=/usr/bin/python3 -m daily_report.scheduled reminder
Type=oneshot
EOF

cat > /etc/systemd/system/kaikai-daily-reminder-followup.timer <<'EOF'
[Unit]
Description=Run Kaikai Daily Report Follow-up Reminder at 18:50

[Timer]
OnCalendar=*-*-* 18:50:00
Persistent=true

[Install]
WantedBy=timers.target
EOF

cat > /etc/systemd/system/kaikai-daily-summary.service <<'EOF'
[Unit]
Description=Kaikai Daily Report Summary

[Service]
WorkingDirectory=/root/kaikai_test
ExecStart=/usr/bin/python3 -m daily_report.scheduled summary
Type=oneshot
EOF

cat > /etc/systemd/system/kaikai-daily-summary.timer <<'EOF'
[Unit]
Description=Run Kaikai Daily Report Summary at 19:00

[Timer]
OnCalendar=*-*-* 19:00:00
Persistent=true

[Install]
WantedBy=timers.target
EOF

systemctl daemon-reload
systemctl enable --now kaikai-daily-reminder.timer
systemctl enable --now kaikai-daily-reminder-followup.timer
systemctl enable --now kaikai-daily-summary.timer
systemctl list-timers --all | grep kaikai || true
