import os
import django
from django.core.files import File

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()

from core.models import PDFSummary

def run():
    file_path = "المراجعة النهائية مستر أحمد الشيخ.pdf"
    if not os.path.exists(file_path):
        print(f"File not found: {file_path}")
        return

    # Check if already exists
    if PDFSummary.objects.filter(title="المراجعة النهائية مستر أحمد الشيخ").exists():
        print("Summary already exists.")
        return

    summary = PDFSummary(
        title="المراجعة النهائية مستر أحمد الشيخ",
        description="ملخص شامل للفصلين الدراسيين الأول والثاني لطلبة الصف الثالث الثانوي الزراعي.",
        level='third',
        price=50.00,  # default price, admin can change it
        payment_instructions="الرجاء تحويل المبلغ على فودافون كاش رقم: 01000000000 وإرفاق صورة الإيصال هنا.",
        is_active=True
    )
    
    with open(file_path, 'rb') as f:
        summary.pdf_file.save("المراجعة_النهائية_مستر_أحمد_الشيخ.pdf", File(f), save=True)
    
    print("PDF Summary successfully imported!")

if __name__ == '__main__':
    run()
