"""
:mod:`etlplus.file.log` module.

Helpers for reading/writing generic log (LOG) files.

Notes
-----
- A LOG file is a plain text file that contains log messages generated by
    applications or systems.
- Common cases:
    - Each line in the file represents a single log entry.
    - Log entries may include timestamps, log levels, and messages.
    - Formats may vary widely depending on the application generating the logs.
- Rule of thumb:
    - If the file is a generic log file, use this module for reading and
        writing.
"""

from __future__ import annotations

from pathlib import Path

from ..types import JSONData
from ..types import JSONList
from . import stub

# SECTION: EXPORTS ========================================================== #


__all__ = [
    'read',
    'write',
]


# SECTION: FUNCTIONS ======================================================== #


def read(
    path: Path,
) -> JSONList:
    """
    Read LOG content from ``path``.

    Parameters
    ----------
    path : Path
        Path to the LOG file on disk.

    Returns
    -------
    JSONList
        The list of dictionaries read from the LOG file.
    """
    return stub.read(path, format_name='LOG')


def write(
    path: Path,
    data: JSONData,
) -> int:
    """
    Write ``data`` to LOG at ``path`` and return record count.

    Parameters
    ----------
    path : Path
        Path to the LOG file on disk.
    data : JSONData
        Data to write as LOG. Should be a list of dictionaries or a
        single dictionary.

    Returns
    -------
    int
        The number of rows written to the LOG file.
    """
    return stub.write(path, data, format_name='LOG')
