"""Rebuild the illustrative DOCX; Python 3 standard library only. CC0 sample."""
from pathlib import Path
from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED

W = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'
R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
P = 'http://schemas.openxmlformats.org/package/2006/relationships'

def paragraph(text, properties='', run_properties=''):
    return f'<w:p><w:pPr>{properties}</w:pPr><w:r><w:rPr>{run_properties}</w:rPr><w:t>{text}</w:t></w:r></w:p>'

body = paragraph('Synthetic conversion check', '<w:pStyle w:val="Heading1"/>')
body += paragraph('Illustrative sample only. No client, employee or financial data.')
body += paragraph('Blue right-aligned source line.', '<w:jc w:val="right"/>', '<w:color w:val="145DA0"/><w:sz w:val="32"/>')
body += '<w:p><w:r><w:t>Keep </w:t></w:r><w:r><w:rPr><w:b/></w:rPr><w:t>bold</w:t></w:r><w:r><w:t> and </w:t></w:r><w:r><w:rPr><w:i/></w:rPr><w:t>italic</w:t></w:r><w:r><w:t> emphasis.</w:t></w:r></w:p>'
body += paragraph('Packing list', '<w:pStyle w:val="Heading2"/>')
for item in ['Paper: 12 sheets', 'Envelopes: 3 pieces']:
    body += paragraph(item, '<w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr>')
body += '<w:tbl><w:tblPr><w:tblW w:w="9360" w:type="dxa"/></w:tblPr><w:tblGrid><w:gridCol w:w="4680"/><w:gridCol w:w="4680"/></w:tblGrid>'
for cells in [('Item', 'Quantity'), ('Paper', '12'), ('Envelopes', '3')]:
    body += '<w:tr>' + ''.join('<w:tc><w:tcPr><w:tcW w:w="4680" w:type="dxa"/></w:tcPr>' + paragraph(cell) + '</w:tc>' for cell in cells) + '</w:tr>'
body += '</w:tbl><w:p><w:hyperlink r:id="rLink"><w:r><w:t>Example link</w:t></w:r></w:hyperlink></w:p>'
body += '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'
body += paragraph('After the source page break', '<w:pStyle w:val="Heading2"/>')
body += paragraph('This paragraph follows an explicit Word page break; check where it lands in the output.')
body += '<w:sectPr><w:headerReference w:type="default" r:id="rHeader"/><w:footerReference w:type="default" r:id="rFooter"/><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"/></w:sectPr>'
parts = {
    '[Content_Types].xml': '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/>' + ''.join(f'<Override PartName="/{name}" ContentType="{ctype}"/>' for name, ctype in [('word/document.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'), ('word/styles.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'), ('word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'), ('word/header1.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'), ('word/footer1.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'), ('docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml')]) + '</Types>',
    '_rels/.rels': f'<Relationships xmlns="{P}"><Relationship Id="rDoc" Type="{R}/officeDocument" Target="word/document.xml"/><Relationship Id="rCore" Type="{P}/metadata/core-properties" Target="docProps/core.xml"/></Relationships>',
    'word/document.xml': f'<w:document xmlns:w="{W}" xmlns:r="{R}"><w:body>{body}</w:body></w:document>',
    'word/_rels/document.xml.rels': f'<Relationships xmlns="{P}">' + ''.join(f'<Relationship Id="{ident}" Type="{R}/{kind}" Target="{target}"/>' for ident, kind, target in [('rStyles','styles','styles.xml'), ('rNumbering','numbering','numbering.xml'), ('rHeader','header','header1.xml'), ('rFooter','footer','footer1.xml')]) + f'<Relationship Id="rLink" Type="{R}/hyperlink" Target="https://example.com/" TargetMode="External"/></Relationships>',
    'word/styles.xml': f'<w:styles xmlns:w="{W}"><w:docDefaults><w:rPrDefault><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial"/><w:sz w:val="22"/></w:rPr></w:rPrDefault></w:docDefaults><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style><w:style w:type="paragraph" w:styleId="Heading1"><w:name w:val="heading 1"/><w:basedOn w:val="Normal"/><w:pPr><w:outlineLvl w:val="0"/></w:pPr><w:rPr><w:b/><w:sz w:val="36"/></w:rPr></w:style><w:style w:type="paragraph" w:styleId="Heading2"><w:name w:val="heading 2"/><w:basedOn w:val="Normal"/><w:pPr><w:outlineLvl w:val="1"/></w:pPr><w:rPr><w:b/><w:sz w:val="28"/></w:rPr></w:style></w:styles>',
    'word/numbering.xml': f'<w:numbering xmlns:w="{W}"><w:abstractNum w:abstractNumId="0"><w:multiLevelType w:val="singleLevel"/><w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="•"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl></w:abstractNum><w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num></w:numbering>',
    'word/header1.xml': f'<w:hdr xmlns:w="{W}">{paragraph("SYNTHETIC HEADER — source only")}</w:hdr>',
    'word/footer1.xml': f'<w:ftr xmlns:w="{W}">{paragraph("SYNTHETIC FOOTER — source only")}</w:ftr>',
    'docProps/core.xml': '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:title>Synthetic FileFinery fixture</dc:title><dc:creator>Synthetic Author Marker</dc:creator></cp:coreProperties>',
}
output = Path(__file__).with_name('synthetic-structure.docx')
with ZipFile(output, 'w') as archive:
    for name, xml in parts.items():
        info = ZipInfo(name, date_time=(2026, 10, 30, 0, 0, 0))
        info.compress_type = ZIP_DEFLATED
        archive.writestr(info, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml)
with ZipFile(output) as archive:
    assert archive.testzip() is None
    assert len(archive.namelist()) == len(parts)
print(f'{output.name}: {output.stat().st_size} bytes')
