#!/usr/bin/env python3
"""KGS-2 Zor Seviye — 50 Soru (Trik Noktalar Odaklı) — Cevaplar eşit dağıtılmış"""

from docx import Document
from docx.shared import Pt, Cm, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml.ns import qn

OUT = "/root/Akademik/İngilizce/5. Sınıf/KGS2_Zor_50_Soru.docx"
doc = Document()

for section in doc.sections:
    section.top_margin = Cm(2)
    section.bottom_margin = Cm(2)
    section.left_margin = Cm(2.5)
    section.right_margin = Cm(2.5)

# ── Title ──
title = doc.add_paragraph()
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = title.add_run("5. SINIF İNGİLİZCE — KGS-2 ZOR SEVİYE")
r.bold = True; r.font.size = Pt(16); r.font.color.rgb = RGBColor(0x1a, 0x47, 0x8a)

sub = doc.add_paragraph()
sub.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = sub.add_run("50 Soru • Trik Noktalar Odaklı • Cevaplar Eşit Dağıtılmış")
r.font.size = Pt(10); r.font.color.rgb = RGBColor(0x66, 0x66, 0x66)
doc.add_paragraph()

def section_header(text):
    p = doc.add_paragraph()
    r = p.add_run(text)
    r.bold = True; r.font.size = Pt(12); r.font.color.rgb = RGBColor(0x1a, 0x47, 0x8a)
    p.paragraph_format.space_before = Pt(10)
    p.paragraph_format.space_after = Pt(6)

def add_q(num, stem, opts):
    p = doc.add_paragraph()
    r = p.add_run(f"{num}. {stem}")
    r.bold = True; r.font.size = Pt(11)
    for o in opts:
        p2 = doc.add_paragraph()
        p2.paragraph_format.left_indent = Cm(1)
        p2.paragraph_format.space_before = Pt(1)
        p2.paragraph_format.space_after = Pt(1)
        r = p2.add_run(o)
        r.font.size = Pt(11)

# ======================= QUESTIONS =======================
# Answers rotated for even distribution: A=13, B=12, C=13, D=12

section_header("BÖLÜM 1: GRAMMAR & VOCABULARY (1-34)")

# Q1 → C (was B)
add_q(1, 'A: Can she play tennis well?\n B: No. She _______ a swimmer.',
    ['A) can', 'B) does', 'C) is', 'D) has'])

# Q2 → D (was B)
add_q(2, 'A: Does he work in a school?\n B: No. He _______ a doctor.',
    ['A) does', 'B) works', 'C) doesn\'t', 'D) is'])

# Q3 → A (was B)
add_q(3, 'A: Is Tom studying for the exam?\n B: No. He _______ to play outside.',
    ['A) wants', 'B) is', 'C) does', 'D) can'])

# Q4 → B (was A)
add_q(4, 'A: Have you got a pet?\n B: Yes. I _______ a cute cat at home.',
    ['A) am', 'B) have got', 'C) can', 'D) has'])

# Q5 → C (was B)
add_q(5, 'A: Are they teachers at this school?\n B: No. They _______ singing in a band.',
    ['A) are', 'B) can', 'C) like', 'D) have'])

# Q6 → D (was B)
add_q(6, 'A: Can he cook Italian food?\n B: No. He _______ learning now.',
    ['A) can', 'B) does', 'C) has', 'D) is'])

# Q7 → A (was B)
add_q(7, 'A: Do they live in Kyrenia?\n B: No. But they _______ visit there often.',
    ['A) can', 'B) do', 'C) are', 'D) have'])

# Q8 → B (was B, stay B)
add_q(8, 'A: Did you go to the party last night?\n B: No. I _______ sick.',
    ['A) did', 'B) was', 'C) went', 'D) am'])

# Q9 → C (was B)
add_q(9, 'A: Was she at the meeting?\n B: No. She _______ want to come.',
    ['A) was', 'B) wasn\'t', 'C) didn\'t', 'D) doesn\'t'])

# Q10 → D (was B)
add_q(10, 'A: Did Tom eat breakfast this morning?\n B: No. He _______ sleeping when I left.',
    ['A) did', 'B) didn\'t', 'C) is', 'D) was'])

# Q11 → A (was B)
add_q(11, 'My father _______ born in 1980 in Nicosia.',
    ['A) was', 'B) is', 'C) were', 'D) did'])

# Q12 → B (was C)
add_q(12, 'We _______ to the museum last weekend and _______ many ancient artefacts.',
    ['A) go / saw', 'B) went / saw', 'C) went / see', 'D) go / see'])

# Q13 → C (was A)
add_q(13, 'I _______ my homework last night because I was too tired.',
    ['A) wasn\'t do', 'B) didn\'t did', 'C) didn\'t do', 'D) not did'])

# Q14 → D (was B)
add_q(14, 'She _______ a glass of milk and then _______ to bed.',
    ['A) drink / go', 'B) drinks / goes', 'C) drank / go', 'D) drank / went'])

# Q15 → A (was A, stay A)
add_q(15, 'They _______ at the park yesterday but they _______ football.',
    ['A) were / didn\'t play', 'B) was / didn\'t played',
     'C) were / not played', 'D) was / didn\'t play'])

# Q16 → B (was B, stay B)
add_q(16, 'We don\'t have _______ milk left. Can you buy _______?',
    ['A) some / any', 'B) any / some', 'C) a / many', 'D) many / a few'])

# Q17 → C (was B)
add_q(17, 'There _______ a lot of rice in the bowl but there _______ many apples.',
    ['A) are / isn\'t', 'B) are / aren\'t', 'C) is / aren\'t', 'D) is / isn\'t'])

# Q18 → D (was B)
add_q(18, 'How _______ sugar do you need for the cake?',
    ['A) many', 'B) some', 'C) any', 'D) much'])

# Q19 → A (was B)
add_q(19, 'There _______ a lot of students in the classroom today.',
    ['A) are', 'B) is', 'C) have', 'D) has'])

# Q20 → B (was B, stay B)
add_q(20, 'Would you like _______ tea? I just made it.',
    ['A) any', 'B) some', 'C) a few', 'D) many'])

# Q21 → C (was B)
add_q(21, 'She _______ wake up early every morning because school starts at 7:30.',
    ['A) have to', 'B) having to', 'C) has to', 'D) had to'])

# Q22 → D (was B)
add_q(22, 'We _______ wear a uniform at our school. It is a rule.',
    ['A) has to', 'B) having to', 'C) had to', 'D) have to'])

# Q23 → A (was A, stay A)
add_q(23, 'My brother is lucky. He _______ do any homework on weekends.',
    ['A) doesn\'t have to', 'B) don\'t have to', 'C) hasn\'t to', 'D) doesn\'t has to'])

# Q24 → B (was C)
add_q(24, 'She _______ a car so she takes the bus to work.',
    ['A) doesn\'t has', 'B) doesn\'t have', 'C) don\'t have', 'D) hasn\'t'])

# Q25 → C (was B)
add_q(25, 'Today is _______ than yesterday. The temperature dropped 5 degrees.',
    ['A) cold', 'B) coldest', 'C) colder', 'D) more cold'])

# Q26 → D (was B)
add_q(26, 'This bag is too small. I need a _______ one.',
    ['A) big', 'B) biggest', 'C) more big', 'D) bigger'])

# Q27 → A (was A, stay A)
add_q(27, 'A: How does the soup _______?\n B: It _______ delicious!',
    ['A) taste / tastes', 'B) tastes / taste', 'C) taste / taste', 'D) tastes / tastes'])

# Q28 → B (was A)
add_q(28, 'This flower _______ beautiful. What is it?',
    ['A) look', 'B) looks', 'C) is looking', 'D) looked'])

# Q29 → C (was B)
add_q(29, 'I always brush my teeth _______ I go to bed.',
    ['A) after', 'B) then', 'C) before', 'D) because'])

# Q30 → D (was B)
add_q(30, '_______ dinner, we watched a movie together.',
    ['A) Before', 'B) Then', 'C) When', 'D) After'])

# Q31 → A (was B)
add_q(31, 'The teacher gave _______ a lot of homework. We were very busy.',
    ['A) us', 'B) we', 'C) our', 'D) they'])

# Q32 → B (was B, stay B)
add_q(32, 'My grandmother lives alone. I visit _______ every weekend.',
    ['A) she', 'B) her', 'C) him', 'D) them'])

# Q33 → C (was A)
add_q(33, 'I am very thirsty. I _______ some water.',
    ['A) want to', 'B) want drink', 'C) want', 'D) to want'])

# Q34 → D (was B)
add_q(34, 'She _______ a doctor when she grows up.',
    ['A) wants', 'B) want to be', 'C) want is', 'D) wants to be'])

# ── PART 2: CLOZE TEST (Q35-42) ──
section_header("BÖLÜM 2: CLOZE TEST (35-42)")

p = doc.add_paragraph()
r = p.add_run("Aşağıdaki parçaları okuyunuz. Boşlukları uygun seçeneklerle doldurunuz.")
r.font.size = Pt(10); r.italic = True

p = doc.add_paragraph()
p.paragraph_format.left_indent = Cm(0.5)
r = p.add_run(
    "Last summer, my family and I (35) _______ to Turkey for a holiday. "
    "The weather (36) _______ very hot but we (37) _______ a great time. "
    "I (38) _______ swimming in the sea every day. "
    "My sister didn't like swimming but she loved the food."
)
r.font.size = Pt(11); r.italic = True

# Q35 → A (was B)
add_q(35, '', ['A) went', 'B) go', 'C) goes', 'D) going'])
# Q36 → B (was C)
add_q(36, '', ['A) is', 'B) was', 'C) were', 'D) are'])
# Q37 → C (was B)
add_q(37, '', ['A) have', 'B) has', 'C) had', 'D) having'])
# Q38 → D (was B)
add_q(38, '', ['A) go', 'B) goes', 'C) going', 'D) went'])

p = doc.add_paragraph()
p.paragraph_format.left_indent = Cm(0.5)
r = p.add_run(
    "Emily wants (39) _______ a chef. She (40) _______ cooking very much. "
    "Yesterday, she (41) _______ a special meal for her family. "
    "There (42) _______ a lot of vegetables in the dish but there wasn't any meat."
)
r.font.size = Pt(11); r.italic = True

# Q39 → A (was B)
add_q(39, '', ['A) to be', 'B) be', 'C) being', 'D) is'])
# Q40 → B (was B, stay B)
add_q(40, '', ['A) like', 'B) likes', 'C) is liking', 'D) liked'])
# Q41 → C (was C, stay C)
add_q(41, '', ['A) make', 'B) makes', 'C) made', 'D) making'])
# Q42 → D (was C)
add_q(42, '', ['A) is', 'B) have', 'C) are', 'D) were'])

# ── PART 3: READING (Q43-50) ──
section_header("BÖLÜM 3: OKUMA-ANLAMA (43-50)")

p = doc.add_paragraph()
r = p.add_run("Aşağıdaki metinleri okuyunuz. Soruları metne göre cevaplayınız.")
r.font.size = Pt(10); r.italic = True

# Passage A
table = doc.add_table(rows=1, cols=1)
cell = table.cell(0, 0)
p = cell.paragraphs[0]
r = p.add_run(
    "My name is Alex. I am 11 years old and I live in Famagusta. "
    "I have to wake up at 6:30 every morning because my school starts at 8:00. "
    "Yesterday was different. I woke up at 7:30 because it was Saturday. "
    "I didn't go to school. Instead, I went to the beach with my family. "
    "The water was cold but I didn't care. I had a lot of fun! "
    "My mother packed some sandwiches and orange juice. "
    "There weren't any apples left at home, so she took some grapes instead. "
    "My little sister wanted to build a sandcastle but she couldn't do it alone. "
    "I helped her and we made a huge sandcastle together. It was a great day."
)
r.font.size = Pt(11); r.italic = True
shading = cell._element.get_or_add_tcPr()
shd = shading.makeelement(qn('w:shd'), {qn('w:val'): 'clear', qn('w:color'): 'auto', qn('w:fill'): 'F0F4F8'})
shading.append(shd)
doc.add_paragraph()

# Q43 → A (was B)
add_q(43, "Why does Alex have to wake up at 6:30 on weekdays?",
    ['A) Because school starts at 8:00', 'B) Because he likes mornings',
     'C) Because he goes to the beach', 'D) Because his mother wakes him up'])
# Q44 → B (was B, stay B)
add_q(44, "Why didn't Alex go to school yesterday?",
    ['A) He was sick', 'B) It was Saturday',
     'C) He went to the beach after school', 'D) He woke up late'])
# Q45 → C (was B)
add_q(45, "What did Alex's mother pack for the beach?",
    ['A) Sandwiches and apples', 'B) Grapes and orange juice',
     'C) Sandwiches and orange juice', 'D) Sandwiches and grapes'])
# Q46 → D (was B)
add_q(46, "What can we understand about Alex from the text?",
    ['A) He doesn\'t like his sister', 'B) He didn\'t go into the water',
     'C) He wants to be a builder', 'D) He helped his sister build a sandcastle'])

# Passage B
table2 = doc.add_table(rows=1, cols=1)
cell2 = table2.cell(0, 0)
p2 = cell2.paragraphs[0]
r2 = p2.add_run(
    "Last week, our class went on a trip to the Kyrenia Castle. "
    "Our teacher said we had to be at school at 7:30. "
    "I was late because my mother didn't wake me up. "
    "I felt very bad when I arrived. My friends were already on the bus. "
    "\"Hurry up, Ali!\" they shouted. \"We are waiting for you!\" "
    "The castle was amazing. There were a lot of old rooms and a big garden. "
    "We saw many historical objects. Our guide told us interesting stories. "
    "I took a lot of photos. After the trip, we ate lunch at a restaurant near the castle. "
    "The food tasted great. I had some pasta and a glass of lemonade. "
    "It cost 150 liras. I paid and we returned to school at 4 o'clock. "
    "I was tired but very happy."
)
r2.font.size = Pt(11); r2.italic = True
shading2 = cell2._element.get_or_add_tcPr()
shd2 = shading2.makeelement(qn('w:shd'), {qn('w:val'): 'clear', qn('w:color'): 'auto', qn('w:fill'): 'F0F4F8'})
shading2.append(shd2)
doc.add_paragraph()

# Q47 → A (was B)
add_q(47, "Why was Ali late for the school trip?",
    ['A) His mother didn\'t wake him up', 'B) He didn\'t want to go',
     'C) He missed the bus', 'D) He was sick'])
# Q48 → B (was B, stay B)
add_q(48, "What did the class do at the castle?",
    ['A) They played games in the garden',
     'B) They saw historical objects and listened to stories',
     'C) They ate lunch inside the castle',
     'D) They took a bus tour around Kyrenia'])
# Q49 → C (was C, stay C)
add_q(49, "How much did Ali's lunch cost?",
    ['A) 100 liras', 'B) 120 liras', 'C) 150 liras', 'D) 200 liras'])
# Q50 → D (was B)
add_q(50, "What is the main idea of the text?",
    ['A) Ali doesn\'t like school trips',
     'B) The castle in Kyrenia is very old',
     'C) School trips are expensive',
     'D) Ali had a wonderful day at the castle despite being late'])

# ======================= ANSWER KEY =======================
doc.add_page_break()
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = p.add_run("CEVAP ANAHTARI — KGS-2 ZOR SEVİYE")
r.bold = True; r.font.size = Pt(14); r.font.color.rgb = RGBColor(0x1a, 0x47, 0x8a)
doc.add_paragraph()

# New answer key with rotated letters
answers = [
    (1,'C','Can → is (kalıp çakışması: soru can, cevap to be)'),
    (2,'D','Does → is (soru does, cevap to be — meslek)'),
    (3,'A','Is → wants to (soru is, cevap want to)'),
    (4,'B','Have you got → I have got (soru kalıbı korunur)'),
    (5,'C','Are → like (soru are, cevap like + Ving)'),
    (6,'D','Can → is + learning (Present Continuous)'),
    (7,'A','Do → can (eylem fiili → can)'),
    (8,'B','Did → was (geçmiş: did yok, durum bildiriyor)'),
    (9,'C','Was → didn\'t want (was soruldu, fiil eylemiyle cevap)'),
    (10,'D','Did → was + sleeping (Past Continuous)'),
    (11,'A','was born — geçmişte doğum, was gerekir'),
    (12,'B','went / saw — geçmişte düzenli ve düzensiz'),
    (13,'C','didn\'t do — didn\'t + V1 (didn\'t did ❌)'),
    (14,'D','drank / went — iki düzensiz fiil, geçmiş zaman'),
    (15,'A','were / didn\'t play — özne çoğul + didn\'t + V1'),
    (16,'B','any (olumsuz) / some (olumlu istek)'),
    (17,'C','rice → is, apples → aren\'t (a lot of + isme bak)'),
    (18,'D','sugar → uncountable → How much'),
    (19,'A','students çoğul → are (a lot of + isme bak)'),
    (20,'B','some — teklif/rica cümlesinde some'),
    (21,'C','She + has to (have to fiile göre çekimlenir)'),
    (22,'D','We + have to'),
    (23,'A','He + doesn\'t have to (don\'t have to ❌)'),
    (24,'B','She doesn\'t have (doesn\'t has ❌, doesn\'t + V1)'),
    (25,'C','colder — tek heceli sıfat + er (more cold ❌)'),
    (26,'D','bigger — büyük-küçük karşılaştırması'),
    (27,'A','How does it taste? (yalın) / It tastes (V1+s)'),
    (28,'B','flower tekil → looks (look ❌, is looking bağlamda yanlış)'),
    (29,'C','before — diş fırçalama yatmadan ÖNCE'),
    (30,'D','After — yemekten SONRA film izleme'),
    (31,'A','gave us — fiilden sonra object pronoun (we ❌)'),
    (32,'B','visit her — grandmother = she → her'),
    (33,'C','want + water (isim → to YOK)'),
    (34,'D','wants to be — She tekil → wants, meslek → to be'),
    (35,'A','Last summer → went (Past Simple)'),
    (36,'B','weather tekil geçmiş → was'),
    (37,'C','had a great time (have → Past = had)'),
    (38,'D','every day ama last summer bağlamı → went'),
    (39,'A','wants to be (want + isimde to, wants + to be)'),
    (40,'B','She + likes (like → V1+s, very much = Present)'),
    (41,'C','Yesterday → made (Past Simple, düzensiz)'),
    (42,'D','vegetables çoğul, geçmiş → were'),
    (43,'A','"...because my school starts at 8:00"'),
    (44,'B','"...it was Saturday"'),
    (45,'C','"My mother packed some sandwiches and orange juice."'),
    (46,'D','"I helped her and we made a huge sandcastle"'),
    (47,'A','"my mother didn\'t wake me up"'),
    (48,'B','"We saw many historical objects. Our guide told us stories."'),
    (49,'C','"It cost 150 liras."'),
    (50,'D','Geç kalmasına rağmen harika bir gün geçirdi'),
]

# Verify distribution
from collections import Counter
dist = Counter(a for _,a,_ in answers)
print(f"Dağılım: A={dist['A']}, B={dist['B']}, C={dist['C']}, D={dist['D']}")

# Answer key in 2-column layout
col1 = answers[:25]
col2 = answers[25:]
for (n1, a1, e1), (n2, a2, e2) in zip(col1, col2):
    p = doc.add_paragraph()
    p.paragraph_format.space_after = Pt(1)
    r = p.add_run(f"Soru {n1}: {a1}")
    r.bold = True; r.font.size = Pt(10)
    r = p.add_run(f"        Soru {n2}: {a2}")
    r.bold = True; r.font.size = Pt(10)

doc.add_paragraph()

# Explanations
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = p.add_run("AÇIKLAMALAR")
r.bold = True; r.font.size = Pt(12); r.font.color.rgb = RGBColor(0x1a, 0x47, 0x8a)
doc.add_paragraph()

for n, a, e in answers:
    p = doc.add_paragraph()
    p.paragraph_format.space_after = Pt(2)
    r = p.add_run(f"Q{n} ({a}): ")
    r.bold = True; r.font.size = Pt(9)
    r = p.add_run(e)
    r.font.size = Pt(9); r.font.color.rgb = RGBColor(0x55, 0x55, 0x55)

doc.save(OUT)
print(f"✅ Kaydedildi: {OUT}")
