#!/usr/bin/env python3
"""5. Sınıf İngilizce — Object Pronouns (Nesne Zamirleri) 50 Soruluk Basit Test
   Parantez ipucu YOK. Seçeneklerde sadece 1 object pronoun → tek doğru garanti.
   Çeldiriciler aynı kişinin subject / possessive formları.
   Cevap dağılımı A/B/C/D tam dengeli. Doğru + Ayrı Cevap Anahtarı DOCX."""

from docx import Document
from docx.shared import Pt, Cm, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
import random

DIR = "/root/Akademik/İngilizce/5. Sınıf/"
OUT_TEST = DIR + "Object_Pronouns_50_Soru.docx"
OUT_KEY = DIR + "Object_Pronouns_50_Soru_Cevaplar.docx"

random.seed(2026)

OBJ = {"I": "me", "you": "you", "he": "him", "she": "her",
       "it": "it", "we": "us", "they": "them"}

# Çeldiriciler: subject formu + possessive formlar (rival object pronoun YOK)
DISTRACT = {
    "me":   ["I", "my", "mine"],
    "you":  ["your", "yours", "you're"],
    "him":  ["he", "his", "he's"],
    "her":  ["she", "hers", "she's"],
    "it":   ["its", "it's", "they"],
    "us":   ["we", "our", "ours"],
    "them": ["they", "their", "theirs"],
}

# ── 50 soru: (cümle, ipucu özne — parantezsiz) ──
Q = [
    ("I like ______ very much.", "she"),
    ("Look at ______! He is my brother.", "he"),
    ("Can you help ______, please?", "I"),
    ("We love ______ very much.", "they"),
    ("Give the ball to ______.", "I"),
    ("This present is for ______.", "you"),
    ("I see ______ every morning.", "he"),
    ("My mother is calling ______.", "we"),
    ("Take ______ to the park.", "it"),
    ("She sits near ______.", "I"),
    ("The teacher speaks to ______.", "we"),
    ("I don't like ______.", "they"),
    ("Please wait for ______.", "she"),
    ("Ali is my friend. I play with ______.", "he"),
    ("Can I come with ______?", "you"),
    ("The dog is hungry. Feed ______.", "it"),
    ("She is my sister. I love ______.", "she"),
    ("We are students. The teacher knows ______.", "we"),
    ("I bought flowers for ______.", "she"),
    ("Do you know ______?", "they"),
    ("He is looking at ______.", "I"),
    ("My father teaches ______ English.", "we"),
    ("I gave ______ a book.", "he"),
    ("This ice cream is for ______.", "I"),
    ("She always helps ______.", "they"),
    ("Look at the cat. It is looking at ______.", "we"),
    ("I met ______ at the party.", "she"),
    ("Can you see ______?", "it"),
    ("Tom and Ali are my friends. I like ______.", "they"),
    ("My grandmother loves ______.", "I"),
    ("Is this letter for ______?", "you"),
    ("We are waiting for ______.", "he"),
    ("The teacher asked ______ a question.", "I"),
    ("I will help ______ with the homework.", "she"),
    ("The children are playing. Watch ______.", "they"),
    ("She lives near ______.", "we"),
    ("I can't find my pen. Can you help ______?", "I"),
    ("This is my dog. I love ______.", "it"),
    ("He is talking to ______.", "she"),
    ("My friends will visit ______ tomorrow.", "we"),
    ("I don't know ______.", "he"),
    ("Please give ______ some water.", "they"),
    ("Come and sit with ______.", "I"),
    ("She bought a gift for ______.", "you"),
    ("The cat is under the table. Can you see ______?", "it"),
    ("We invited ______ to our party.", "he"),
    ("My brother is calling ______.", "we"),
    ("I like ______ very much.", "you"),
    ("Don't forget ______!", "they"),
    ("She is my best friend. I trust ______.", "she"),
]

assert len(Q) == 50, len(Q)

# ── Dengeli harf slotları (13/13/12/12) ──
letters = ["A"] * 13 + ["B"] * 13 + ["C"] * 12 + ["D"] * 12
random.shuffle(letters)

LETTERS = ["A", "B", "C", "D"]
built = []
dist = {"A": 0, "B": 0, "C": 0, "D": 0}

for (sentence, subj), correct_letter in zip(Q, letters):
    correct = OBJ[subj]
    opts = [correct] + DISTRACT[correct]
    assert len(set(opts)) == 4, (correct, opts)
    opts.remove(correct)
    random.shuffle(opts)
    idx = LETTERS.index(correct_letter)
    opts.insert(idx, correct)
    assert len(opts) == 4 and len(set(opts)) == 4
    # tek doğru kontrolü: seçenekler arasında başka object pronoun var mı?
    others = [o for o in opts if o in OBJ.values() and o != correct]
    assert not others, (sentence, opts)
    dist[correct_letter] += 1
    built.append({"sentence": sentence, "opts": opts,
                  "answer": correct_letter, "correct": correct})

def setup(doc):
    for s in doc.sections:
        s.top_margin = Cm(2); s.bottom_margin = Cm(2)
        s.left_margin = Cm(2.5); s.right_margin = Cm(2.5)
    st = doc.styles["Normal"]; st.font.name = "Calibri"; st.font.size = Pt(11)

# ── TEST DOCX ──
doc = Document(); setup(doc)
h = doc.add_heading("5. Sınıf İngilizce — Object Pronouns (Nesne Zamirleri)", level=1)
h.alignment = WD_ALIGN_PARAGRAPH.CENTER
sub = doc.add_paragraph(); sub.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = sub.add_run("50 Soru • 4 Seçenekli • Basit Seviye • Cevap Anahtarı Ayrı Dosyada")
r.font.size = Pt(10); r.font.color.rgb = RGBColor(100, 100, 100)
doc.add_paragraph()

for i, q in enumerate(built, 1):
    p = doc.add_paragraph()
    rr = p.add_run(f"{i}. "); rr.bold = True
    p.add_run(q["sentence"]).font.size = Pt(11)
    for letter, text in zip(LETTERS, q["opts"]):
        po = doc.add_paragraph(); po.paragraph_format.left_indent = Cm(1)
        po.add_run(f"{letter}) {text}").font.size = Pt(11)
    doc.add_paragraph()

doc.save(OUT_TEST)

# ── CEVAP ANAHTARI DOCX ──
kdoc = Document(); setup(kdoc)
kh = kdoc.add_heading("Object Pronouns — Cevap Anahtarı", level=1)
kh.alignment = WD_ALIGN_PARAGRAPH.CENTER
kdoc.add_paragraph()

for i, q in enumerate(built, 1):
    p = kdoc.add_paragraph()
    rr = p.add_run(f"{i}. {q['answer']}"); rr.bold = True; rr.font.size = Pt(11)
    p.add_run(f"  →  {q['correct']}").font.size = Pt(11)

kdoc.add_paragraph()
p = kdoc.add_paragraph(); r = p.add_run("📋 Kapsam Notu:"); r.bold = True; r.font.size = Pt(9)
kdoc.add_paragraph().add_run(
    "• Konu: Object Pronouns (me, you, him, her, it, us, them) — 5. Sınıf\n"
    "• Kural: Fiilden sonra ve edattan (at, for, with, to...) sonra NESNE zamiri gelir.\n"
    "• Çeldiriciler: aynı kişinin subject (I/he/she...) ve possessive (my/his/her...) formları.\n"
    "• Seçeneklerde tek bir object pronoun var → cevap nettir.\n"
    "• Zorluk: A1 (çok basit)\n"
    "• Kaynak: KKTC MEB Temel Eğitim İngilizce Öğretim Programı (5. Sınıf)"
).font.size = Pt(9)

kdoc.save(OUT_KEY)

print("TEST:", OUT_TEST)
print("KEY :", OUT_KEY)
print("Dağılım:", dist)
