# autogenerated file, do not modify
{% import 'macros.jinja' as macros %}
{% set parent = dfn|parent(name) %}
{% set title = (name|title).title() %}
{% set description = name|description %}
{% set container = dfn.ref is defined and name[0] not in ["sln", "sim"] and name[1] not in ["hpc"] %}

from os import PathLike, curdir
from typing import Union

from flopy.mf6.data.mfdatautil import ArrayTemplateGenerator, ListTemplateGenerator
from flopy.mf6.mfpackage import MFChildPackages, MFPackage


class Modflow{{ title }}(MFPackage):
    """
    {{ description }}

    Parameters
    ----------
    {{ parent }}
        {{ parent|capitalize }} that this package is a part of. Package is automatically
        added to {{ parent }} when it is initialized.
    loading_package : bool, default False
        Do not set this parameter. It is intended for debugging and internal
        processing purposes only.
{{ macros.docstrings(dfn|variables)|indent(4, first=true) }}
    filename : str or PathLike, optional
        Name or path of file where this package is stored.
    pname : str, optional
        Package name.
    **kwargs
        Extra keywords for :class:`flopy.mf6.mfpackage.MFPackage`.

    """

    {% for attr in dfn|attrs(name) %}
    {{ attr }}
    {% endfor %}

    def __init__(
        self,
        {{ parent }},
        loading_package=False,
{{ macros.init_params(dfn|variables, skip=name|skip_init)|indent(8, first=true) }}
        filename=None,
        pname=None,
        **kwargs,
    ):
        """Initialize Modflow{{ title }}."""
        super().__init__(
            parent={{ parent }},
            package_type="{{ name[1] }}",
            filename=filename,
            pname=pname,
            loading_package=loading_package,
            **kwargs,
        )

        {% for statement in dfn|init(name) %}
        {{ statement }}
        {% endfor %}

        self._init_complete = True

{% if container %}
class {{ title }}Packages(MFChildPackages):
    """
    {{ title }}Packages is a container class for the Modflow{{ title }} class.
    """
    package_abbr = "{{ title.lower() }}packages"

    def initialize(
        self,
{{ macros.init_params(dfn|variables, alias=true, skip=name|skip_init)|indent(8, first=true) }}
        filename=None,
        pname=None,
    ):
        """
        Initialize a new Modflow{{ title }} package, removing any sibling
        child packages attached to the same parent package.

        See :class:`Modflow{{ title }}` for parameter definitions.
        """
        new_package = Modflow{{ title }}(
            self._cpparent,
            {% for n, var in (dfn|variables).items() if n not in name|skip_init %}
            {{ n|safe_name }}={{ n|safe_name }},
            {% endfor %}
            filename=filename,
            pname=pname,
            child_builder_call=True,
        )
        self.init_package(new_package, filename)

    {% if name[1] != "obs" %}
    def append_package(
        self,
{{ macros.init_params(dfn|variables, alias=true, skip=name|skip_init)|indent(8, first=true) }}
        filename=None,
        pname=None,
    ):
        """
        Add a new Modflow{{ title }} package to the container.

        See :class:`Modflow{{ title }}` for parameter definitions.
        """
        new_package = Modflow{{ title }}(
            self._cpparent,
            {% for n, var in (dfn|variables).items() if n not in name|skip_init %}
            {{ n|safe_name }}={{ n|safe_name }},
            {% endfor %}
            filename=filename,
            pname=pname,
            child_builder_call=True,
        )
        self._append_package(new_package, filename)
    {% endif %}
{% endif %}
