from django.core.management.base import BaseCommand
from django.utils import timezone
from datetime import timedelta
import os


class Command(BaseCommand):
    def handle(self, *args, **options):
        log_files = [
            '/logs/appointment_reminders.log',
            '/logs/followup_messages.log',
            '/logs/daily_report.log'
        ]


        for log_file in log_files:
            if os.path.exists(log_file):
                mod_time = os.path.getmtime(log_file)
                last_run = timezone.datetime.fromtimestamp(mod_time)
                hours_ago = (timezone.now() - last_run).total_seconds() / 3600

                self.stdout.write(f"{log_file}: آخرین اجرا {hours_ago:.1f} ساعت پیش")
            else:
                self.stdout.write(f"{log_file}: فایل وجود ندارد")