#!/usr/bin/env python3
"""4. Sınıf Unit 7 - Food and Meals — PDF"""

from fpdf import FPDF
import os

OUT = "/root/Akademik/İngilizce/4. Sınıf/Unit7_Food_and_Meals_Test.pdf"

pdf = FPDF()
pdf.add_page()
pdf.set_auto_page_break(auto=True, margin=20)

# ── Turkish character support ──
pdf.add_font("DejaVu", "", "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", uni=True)
pdf.add_font("DejaVu", "B", "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", uni=True)

# ── Header ──
pdf.set_font("DejaVu", "B", 16)
pdf.cell(0, 10, "4. Sınıf İngilizce — Ünite 7: Food and Meals", align="C", new_x="LMARGIN", new_y="NEXT")
pdf.set_font("DejaVu", "", 9)
pdf.set_text_color(100, 100, 100)
pdf.cell(0, 6, "KGS Hazırlık Testi • 10 Soru • 4 Seçenekli", align="C", new_x="LMARGIN", new_y="NEXT")
pdf.set_text_color(0, 0, 0)
pdf.ln(6)

questions = [
    {
        "q": "A: ______ I have some water, please?\nB: Of course. Here you are.",
        "a": "Can", "b": "Do", "c": "Am", "d": "Is",
        "answer": "A",
        "topic": "Polite request — Can I have...?",
        "trick": "Can vs Do/Am/Is karıştırma (4. Sınıf Trik #4)"
    },
    {
        "q": "A: What would you like to eat?\nB: ______ a sandwich, please.",
        "a": "I'd like", "b": "I like", "c": "I am", "d": "I have",
        "answer": "A",
        "topic": "I'd like vs I like (istek vs tercih)",
        "trick": "'I'd like' = kibarca istek, 'I like' = genel tercih (4. Sınıf Trik #5)"
    },
    {
        "q": "My brother ______ want any milk. He prefers juice.",
        "a": "doesn't", "b": "don't", "c": "isn't", "d": "aren't",
        "answer": "A",
        "topic": "Present Simple negative (he/she/it → doesn't)",
        "trick": "doesn't'tan sonra fiil YALIN — 'doesn't wants' ❌ (4. Sınıf Trik #10a)"
    },
    {
        "q": "A: Do you like bananas?\nB: Yes, I ______. They are delicious!",
        "a": "do", "b": "like", "c": "am", "d": "have",
        "answer": "A",
        "topic": "Yes/No questions — short answers",
        "trick": "\"Yes, I do.\" — \"Yes, I like.\" ❌ (4. Sınıf Trik #20)"
    },
    {
        "q": "She ______ apples and oranges every morning.",
        "a": "likes", "b": "like", "c": "is liking", "d": "don't like",
        "answer": "A",
        "topic": "Present Simple — he/she/it + V1+s",
        "trick": "She like ❌ → She likes ✅ (4. Sınıf Trik #3)"
    },
    {
        "q": "Would you like tea ______ coffee?",
        "a": "or", "b": "and", "c": "but", "d": "because",
        "answer": "A",
        "topic": "Conjunctions: or (seçenek sunma)",
        "trick": "\"or\" = seçenek, \"and\" = ekleme — bağlama dikkat (4. Sınıf Trik #19)"
    },
    {
        "q": "A: Where do bananas come ______?\nB: They come from Costa Rica.",
        "a": "from", "b": "in", "c": "at", "d": "on",
        "answer": "A",
        "topic": "Preposition — come from",
        "trick": "\"come from\" kalıbı — \"come in/at/on\" olmaz"
    },
    {
        "q": "Look! The children ______ lunch in the garden now.",
        "a": "are having", "b": "have", "c": "has", "d": "is having",
        "answer": "A",
        "topic": "Present Continuous — look! + right now",
        "trick": "\"Look!\" → Present Continuous zorunlu. \"have\" ❌ (4. Sınıf Trik #2)"
    },
    {
        "q": "There ______ a lot of rice on the plate.",
        "a": "is", "b": "are", "c": "am", "d": "have",
        "answer": "A",
        "topic": "There is/are + uncountable noun",
        "trick": "rice = sayılamaz → is. \"a lot of\"a değil isme bak! (4. Sınıf Trik #12a)"
    },
    {
        "q": "A: What is your favourite food?\nB: I love ______ vegetables. They are very healthy.",
        "a": "eating", "b": "eat", "c": "eats", "d": "ate",
        "answer": "A",
        "topic": "love + Ving (gerund)",
        "trick": "love'dan sonra fiil -ing alır — \"love eat\" ❌ (4. Sınıf Trik #11)"
    },
]

# ── Print each question ──
for i, q in enumerate(questions, 1):
    # Question header
    pdf.set_font("DejaVu", "B", 11)
    pdf.cell(0, 7, f"Question {i}", new_x="LMARGIN", new_y="NEXT")
    
    # Question text
    pdf.set_font("DejaVu", "", 10)
    # Handle multi-line questions
    for line in q["q"].split("\n"):
        pdf.multi_cell(0, 6, line, new_x="LMARGIN", new_y="NEXT")
    
    pdf.ln(2)
    
    # Options
    for letter in ["a", "b", "c", "d"]:
        pdf.set_font("DejaVu", "", 10)
        pdf.cell(10, 7, "", new_x="RIGHT", new_y="LAST")  # indent
        pdf.cell(6, 7, f"{letter.upper()})", new_x="RIGHT", new_y="LAST")
        pdf.cell(0, 7, f"   {q[letter]}", new_x="LMARGIN", new_y="NEXT")
    
    pdf.ln(5)

# ── Answer Key ──
pdf.add_page()
pdf.set_font("DejaVu", "B", 14)
pdf.cell(0, 10, "Cevap Anahtarı", align="C", new_x="LMARGIN", new_y="NEXT")
pdf.ln(8)

for i, q in enumerate(questions, 1):
    pdf.set_font("DejaVu", "B", 10)
    pdf.cell(0, 6, f"Q{i}: {q['answer']}  →  {q[q['answer'].lower()]}", new_x="LMARGIN", new_y="NEXT")
    
    pdf.set_font("DejaVu", "", 8)
    pdf.set_text_color(100, 100, 100)
    pdf.cell(0, 5, f"     Konu: {q['topic']}", new_x="LMARGIN", new_y="NEXT")
    
    pdf.set_text_color(180, 60, 20)
    pdf.set_font("DejaVu", "", 8)
    pdf.cell(0, 5, f"     ⚡ Trik: {q['trick']}", new_x="LMARGIN", new_y="NEXT")
    pdf.set_text_color(0, 0, 0)
    pdf.ln(3)

pdf.ln(8)
pdf.set_font("DejaVu", "B", 8)
pdf.cell(0, 5, "Kapsam Notu:", new_x="LMARGIN", new_y="NEXT")
pdf.set_font("DejaVu", "", 7)
pdf.set_text_color(80, 80, 80)
notes = [
    "• Sorular yalnızca 7. ünite + önceki ünitelerde (1-6) işlenen konulardan hazırlanmıştır.",
    "• Öğrencilerin ileride göreceği konular KESİNLİKLE sorulmamıştır.",
    "• Çeldiriciler, 4. Sınıf Trik Noktalar dosyasındaki sık yapılan hatalara göre yerleştirilmiştir.",
    "• Zorluk seviyesi: A1",
    "• Kaynak: KKTC MEB Temel Eğitim İngilizce Dersi Öğretim Programı (4. Sınıf)",
]
for n in notes:
    pdf.cell(0, 4, n, new_x="LMARGIN", new_y="NEXT")

pdf.output(OUT)
print(f"✅ PDF kaydedildi: {OUT}")
