"""Type stubs for hwpers Python bindings."""

from __future__ import annotations
from typing import List, Optional, Union

# ============================================================================
# Enums
# ============================================================================

class TextAlign:
    Left: TextAlign
    Center: TextAlign
    Right: TextAlign
    Justify: TextAlign
    Distribute: TextAlign

class ParagraphAlignment:
    Left: ParagraphAlignment
    Center: ParagraphAlignment
    Right: ParagraphAlignment
    Justify: ParagraphAlignment
    Distribute: ParagraphAlignment

class ListType:
    Bullet: ListType
    Numbered: ListType
    Alphabetic: ListType
    Roman: ListType
    Korean: ListType

class BorderLineType:
    """Border line type options."""
    None_: BorderLineType
    Solid: BorderLineType
    Dashed: BorderLineType
    Dotted: BorderLineType
    Double: BorderLineType
    Thick: BorderLineType

class ImageFormat:
    Jpeg: ImageFormat
    Png: ImageFormat
    Bmp: ImageFormat
    Gif: ImageFormat

class ImageAlign:
    Left: ImageAlign
    Center: ImageAlign
    Right: ImageAlign
    InlineWithText: ImageAlign

class PageOrientation:
    Portrait: PageOrientation
    Landscape: PageOrientation

class PaperSize:
    A3: PaperSize
    A4: PaperSize
    A5: PaperSize
    B4: PaperSize
    B5: PaperSize
    Letter: PaperSize
    Legal: PaperSize
    Tabloid: PaperSize
    Custom: PaperSize

class PageNumberFormat:
    Numeric: PageNumberFormat
    AlphaUpper: PageNumberFormat
    AlphaLower: PageNumberFormat
    RomanUpper: PageNumberFormat
    RomanLower: PageNumberFormat

class HyperlinkType:
    Url: HyperlinkType
    Email: HyperlinkType
    File: HyperlinkType
    Bookmark: HyperlinkType
    ExternalBookmark: HyperlinkType

class HyperlinkDisplay:
    TextOnly: HyperlinkDisplay
    UrlOnly: HyperlinkDisplay
    Both: HyperlinkDisplay

class PageApplyType:
    All: PageApplyType
    FirstPage: PageApplyType
    OddPages: PageApplyType
    EvenPages: PageApplyType

class HeaderFooterAlignment:
    Left: HeaderFooterAlignment
    Center: HeaderFooterAlignment
    Right: HeaderFooterAlignment

class TextBoxAlignment:
    Left: TextBoxAlignment
    Center: TextBoxAlignment
    Right: TextBoxAlignment
    Inline: TextBoxAlignment
    Absolute: TextBoxAlignment

class TextBoxBorderStyle:
    """Text box border style options."""
    None_: TextBoxBorderStyle
    Solid: TextBoxBorderStyle
    Dashed: TextBoxBorderStyle
    Dotted: TextBoxBorderStyle
    Double: TextBoxBorderStyle

class CellAlign:
    Left: CellAlign
    Center: CellAlign
    Right: CellAlign

# ============================================================================
# Style Classes
# ============================================================================

class TextStyle:
    """Text styling options with method chaining support."""
    def __init__(self) -> None: ...
    def bold(self) -> TextStyle: ...
    def italic(self) -> TextStyle: ...
    def underline(self) -> TextStyle: ...
    def strikethrough(self) -> TextStyle: ...
    def size(self, pt: int) -> TextStyle: ...
    def color(self, rgb: int) -> TextStyle: ...
    def background_color(self, rgb: int) -> TextStyle: ...
    def font_name(self, name: str) -> TextStyle: ...

class BorderLineStyle:
    """Border line styling."""
    def __init__(
        self,
        line_type: BorderLineType = ...,
        width: int = ...,
        color: int = ...
    ) -> None: ...

class CellBorderStyle:
    """Table cell border styling."""
    def __init__(self) -> None: ...

class ImageOptions:
    """Image insertion options."""
    width: int
    height: int
    alignment: ImageAlign
    def __init__(self) -> None: ...

class StyledText:
    """Text with associated style."""
    def __init__(self, text: str, style: TextStyle) -> None: ...

class HyperlinkStyle:
    """Hyperlink styling."""
    def __init__(self) -> None: ...

class Hyperlink:
    """Hyperlink configuration."""
    @staticmethod
    def url(text: str, url: str) -> Hyperlink: ...
    @staticmethod
    def email(text: str, email: str) -> Hyperlink: ...
    @staticmethod
    def file(text: str, path: str) -> Hyperlink: ...
    @staticmethod
    def bookmark(text: str, bookmark: str) -> Hyperlink: ...

class FloatingTextBoxStyle:
    """Floating text box styling."""
    def __init__(self) -> None: ...

class CustomTextBoxStyle:
    """Custom text box styling."""
    def __init__(
        self,
        alignment: TextBoxAlignment = ...,
        border_style: TextBoxBorderStyle = ...,
        border_color: int = ...,
        background_color: int = ...
    ) -> None: ...

class PageMargins:
    """Page margin presets."""
    @staticmethod
    def normal() -> PageMargins: ...
    @staticmethod
    def narrow() -> PageMargins: ...
    @staticmethod
    def wide() -> PageMargins: ...

class PageLayout:
    """Page layout configuration."""
    @staticmethod
    def a4_portrait() -> PageLayout: ...
    @staticmethod
    def a4_landscape() -> PageLayout: ...
    @staticmethod
    def letter_portrait() -> PageLayout: ...
    @staticmethod
    def letter_landscape() -> PageLayout: ...
    def with_margins(self, margins: PageMargins) -> PageLayout: ...

class HeadingStyle:
    """Heading style configuration."""
    def __init__(
        self,
        level: int = ...,
        font_size: int = ...,
        bold: bool = ...,
        color: int = ...
    ) -> None: ...

class ListStyle:
    """List style configuration."""
    def __init__(
        self,
        list_type: ListType = ...,
        indent: int = ...,
        spacing: int = ...
    ) -> None: ...

class TableStyle:
    """Table style configuration."""
    def __init__(
        self,
        border_style: CellBorderStyle = ...,
        cell_padding: int = ...,
        header_background: int = ...
    ) -> None: ...

class TextRange:
    """Text range for hyperlinks within paragraphs."""
    def __init__(self, start: int, end: int, url: str) -> None: ...

# ============================================================================
# TableBuilder
# ============================================================================

class TableBuilder:
    """Fluent API for building tables."""
    row_count: int
    col_count: int

    def __init__(self, rows: int, cols: int) -> None: ...
    def set_cell(self, row: int, col: int, text: str) -> TableBuilder: ...
    def set_header_row(self, texts: List[str]) -> TableBuilder: ...
    def merge_cells(self, row: int, start_col: int, end_col: int) -> TableBuilder: ...
    def set_outer_borders(self, style: CellBorderStyle) -> TableBuilder: ...
    def set_inner_borders(self, style: CellBorderStyle) -> TableBuilder: ...
    def set_all_borders(self, style: CellBorderStyle) -> TableBuilder: ...
    def no_borders(self) -> TableBuilder: ...

# ============================================================================
# Render Classes
# ============================================================================

class RenderOptions:
    """Rendering options."""
    def __init__(self) -> None: ...

class RenderedPage:
    """A rendered page."""
    def width(self) -> int: ...
    def height(self) -> int: ...
    def to_png(self) -> bytes: ...

class RenderResult:
    """Result of document rendering."""
    def page_count(self) -> int: ...
    def page(self, index: int) -> RenderedPage: ...

# ============================================================================
# Document Classes
# ============================================================================

class HwpDocument:
    """A parsed HWP document."""
    def extract_text(self) -> str: ...
    def section_count(self) -> int: ...
    def get_title(self) -> Optional[str]: ...
    def get_author(self) -> Optional[str]: ...
    def get_page_count(self) -> int: ...
    def get_character_count(self) -> int: ...
    def is_compressed(self) -> bool: ...
    def render(self, options: RenderOptions) -> RenderResult: ...
    def to_svg(self) -> str: ...

class HwpWriter:
    """Create and write HWP documents."""
    def __init__(self) -> None: ...

    # Document metadata
    def set_title(self, title: str) -> None: ...
    def set_author(self, author: str) -> None: ...
    def set_subject(self, subject: str) -> None: ...
    def set_keywords(self, keywords: str) -> None: ...
    def set_company(self, company: str) -> None: ...

    # Page layout
    def set_a4_portrait(self) -> None: ...
    def set_a4_landscape(self) -> None: ...
    def set_letter_portrait(self) -> None: ...
    def set_letter_landscape(self) -> None: ...
    def set_page_layout(self, layout: PageLayout) -> None: ...
    def set_paper_size(self, size: PaperSize) -> None: ...
    def set_page_orientation(self, orientation: PageOrientation) -> None: ...
    def set_custom_page_size(self, width: int, height: int) -> None: ...
    def set_custom_page_size_mm(self, width: float, height: float) -> None: ...
    def get_page_layout(self) -> PageLayout: ...

    # Margins
    def set_normal_margins(self) -> None: ...
    def set_narrow_margins(self) -> None: ...
    def set_wide_margins(self) -> None: ...
    def set_page_margins_mm(self, top: float, bottom: float, left: float, right: float) -> None: ...
    def set_page_margins_inches(self, top: float, bottom: float, left: float, right: float) -> None: ...

    # Paragraphs
    def add_paragraph(self, text: str) -> None: ...
    def add_paragraph_with_style(self, text: str, style: TextStyle) -> None: ...
    def add_styled_paragraph(self, styled_texts: List[StyledText]) -> None: ...
    def add_aligned_paragraph(self, text: str, alignment: ParagraphAlignment) -> None: ...
    def add_paragraph_with_bold(self, text: str) -> None: ...
    def add_paragraph_with_colors(self, text: str, text_color: int, bg_color: int) -> None: ...
    def add_paragraph_with_highlight(self, text: str, color: int) -> None: ...
    def add_paragraph_with_spacing(self, text: str, line_spacing: int, para_spacing: int) -> None: ...
    def add_mixed_text(self, styled_texts: List[StyledText]) -> None: ...

    # Headings
    def add_heading(self, text: str, level: int) -> None: ...

    # Lists
    def add_bullet_list(self, items: List[str]) -> None: ...
    def add_numbered_list(self, items: List[str]) -> None: ...
    def add_list(self, items: List[str], list_type: ListType) -> None: ...
    def start_list(self, list_type: ListType) -> None: ...
    def start_nested_list(self, list_type: ListType) -> None: ...
    def add_list_item(self, text: str) -> None: ...
    def end_list(self) -> None: ...

    # Tables
    def add_table(self, data: List[List[str]]) -> None: ...
    def add_simple_table(self, rows: int, cols: int, data: List[str]) -> None: ...
    def add_table_with_builder(self, builder: TableBuilder) -> None: ...

    # Hyperlinks
    def add_hyperlink(self, text: str, url: str) -> None: ...
    def add_hyperlink_with_options(self, hyperlink: Hyperlink) -> None: ...
    def add_custom_hyperlink(self, text: str, url: str, style: HyperlinkStyle) -> None: ...
    def add_email_link(self, text: str, email: str) -> None: ...
    def add_file_link(self, text: str, path: str) -> None: ...
    def add_bookmark_link(self, text: str, bookmark: str) -> None: ...
    def add_paragraph_with_hyperlinks(self, text: str, ranges: List[TextRange]) -> None: ...

    # Images
    def add_image(self, path: str) -> None: ...
    def add_image_with_options(self, path: str, options: ImageOptions) -> None: ...
    def add_image_from_bytes(self, data: bytes, format: ImageFormat) -> None: ...

    # Text boxes
    def add_text_box(self, text: str) -> None: ...
    def add_text_box_at_position(self, text: str, x: int, y: int, width: int, height: int) -> None: ...
    def add_floating_text_box(self, text: str, style: FloatingTextBoxStyle) -> None: ...
    def add_styled_text_box(self, text: str, style: TextStyle) -> None: ...
    def add_custom_text_box(self, text: str, x: int, y: int, width: int, height: int, style: CustomTextBoxStyle) -> None: ...

    # Headers and footers
    def add_header(self, text: str) -> None: ...
    def add_footer(self, text: str) -> None: ...
    def add_header_with_options(self, text: str, apply_type: PageApplyType, alignment: HeaderFooterAlignment) -> None: ...
    def add_footer_with_options(self, text: str, apply_type: PageApplyType, alignment: HeaderFooterAlignment) -> None: ...
    def add_header_with_page_number(self) -> None: ...
    def add_footer_with_page_number(self) -> None: ...

    # Page numbering
    def set_page_numbering(self, start_page: int, format: PageNumberFormat) -> None: ...

    # Other settings
    def set_columns(self, count: int) -> None: ...
    def set_page_background_color(self, color: int) -> None: ...
    def update_statistics(self) -> None: ...

    # Output
    def save(self, path: str) -> None: ...
    def to_bytes(self) -> bytes: ...
    def extract_text(self) -> str: ...

# ============================================================================
# Functions
# ============================================================================

def read_file(path: str) -> HwpDocument:
    """Read an HWP document from a file path."""
    ...

def read_bytes(data: bytes) -> HwpDocument:
    """Read an HWP document from bytes."""
    ...

def mm_to_hwp_units(mm: float) -> int:
    """Convert millimeters to HWP units."""
    ...

def hwp_units_to_mm(units: int) -> float:
    """Convert HWP units to millimeters."""
    ...

def inches_to_hwp_units(inches: float) -> int:
    """Convert inches to HWP units."""
    ...

def hwp_units_to_inches(units: int) -> float:
    """Convert HWP units to inches."""
    ...
