"""
hello_docx.py — SmartScribe.Docx SDK Python quick-start

Requires: smartscribe_docx.py on sys.path and SmartScribeDocx.dll
          in the same folder or on the system PATH.

Usage:
    python hello_docx.py sample.docx
"""

import sys
from smartscribe_docx import SmartScribeDocx

path = sys.argv[1] if len(sys.argv) > 1 else "sample.docx"
print(f"SmartScribe.Docx SDK — opening {path}")

with SmartScribeDocx(path) as doc:
    m = doc.get_margins()
    print(f"Margins: top={m['top']} bottom={m['bottom']} left={m['left']} right={m['right']}")

    # 1-inch margins (1440 twips = 1 inch)
    doc.set_margins(top=1440, bottom=1440, left=1440, right=1440,
                    header_dist=709, footer_dist=709, gutter=0, mirror=0)

    doc.set_doc_property("title",  "My Document")
    doc.set_doc_property("author", "Dan Shields")

    hdr = doc.build_hf_xml(is_header=True, template="Page {PAGE} of {NUMPAGES}", alignment="right")
    doc.set_header_xml(hf_type=0, xml_bytes=hdr)

    ftr = doc.build_hf_xml(is_header=False, template="{AUTHOR}  |  {TITLE}", alignment="center")
    doc.set_footer_xml(hf_type=0, xml_bytes=ftr)

    doc.save_as("output.docx")
    print("Saved to output.docx")
