# autogenerated file, do not modify

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 ModflowMvr(MFPackage):
    """
    ModflowMvr defines a MVR package.

    Parameters
    ----------
    parent_model_or_package
        Parent_model_or_package that this package is a part of. Package is automatically
        added to parent_model_or_package when it is initialized.
    loading_package : bool, default False
        Do not set this parameter. It is intended for debugging and internal
        processing purposes only.
    print_input : keyword
        keyword to indicate that the list of mvr information will be written to the
        listing file immediately after it is read.
    print_flows : keyword
        keyword to indicate that the list of mvr flow rates will be printed to the
        listing file for every stress period time step in which 'budget print' is
        specified in output control.  if there is no output control option and
        'print_flows' is specified, then flow rates are printed for the last time step
        of each stress period.
    modelnames : keyword
        keyword to indicate that all package names will be preceded by the model name
        for the package.  model names are required when the mover package is used with
        a gwf-gwf exchange.  the modelname keyword should not be used for a mover
        package that is for a single gwf model.
    budget_filerecord : record
    budgetcsv_filerecord : record
    maxmvr : integer
        integer value specifying the maximum number of water mover entries that will
        specified for any stress period.
    maxpackages : integer
        integer value specifying the number of unique packages that are included in
        this water mover input file.
    packages : [(mname, pname)]
        * mname : string
                name of model containing the package.  Model names are assigned by the user in
                the simulation name file.
        * pname : string
                is the name of a package that may be included in a subsequent stress period
                block.  The package name is assigned in the name file for the GWF Model.
                Package names are optionally provided in the name file.  If they are not
                provided by the user, then packages are assigned a default value, which is the
                package acronym followed by a hyphen and the package number.  For example, the
                first Drain Package is named DRN-1.  The second Drain Package is named DRN-2,
                and so forth.

    perioddata : [(mname1, pname1, id1, mname2, pname2, id2, mvrtype, value)]
        * mname1 : string
                name of model containing the package, PNAME1.
        * pname1 : string
                is the package name for the provider.  The package PNAME1 must be designated to
                provide water through the MVR Package by specifying the keyword 'MOVER' in its
                OPTIONS block.
        * id1 : integer
                is the identifier for the provider.  For the standard boundary packages, the
                provider identifier is the number of the boundary as it is listed in the
                package input file. (Note that the order of these boundaries may change by
                stress period, which must be accounted for in the Mover Package.)  So the first
                well has an identifier of one.  The second is two, and so forth.  For the
                advanced packages, the identifier is the reach number (SFR Package), well
                number (MAW Package), or UZF cell number.  For the Lake Package, ID1 is the
                lake outlet number.  Thus, outflows from a single lake can be routed to
                different streams, for example.
        * mname2 : string
                name of model containing the package, PNAME2.
        * pname2 : string
                is the package name for the receiver.  The package PNAME2 must be designated to
                receive water from the MVR Package by specifying the keyword 'MOVER' in its
                OPTIONS block.
        * id2 : integer
                is the identifier for the receiver.  The receiver identifier is the reach
                number (SFR Package), Lake number (LAK Package), well number (MAW Package), or
                UZF cell number.
        * mvrtype : string
                is the character string signifying the method for determining how much water
                will be moved.  Supported values are 'FACTOR' 'EXCESS' 'THRESHOLD' and 'UPTO'.
                These four options determine how the receiver flow rate, :math:`Q_R`, is
                calculated.  These options mirror the options defined for the cprior variable
                in the SFR package, with the term 'FACTOR' being functionally equivalent to the
                'FRACTION' option for cprior.
        * value : double precision
                is the value to be used in the equation for calculating the amount of water to
                move.  For the 'FACTOR' option, VALUE is the :math:`alpha` factor.  For the
                remaining options, VALUE is the specified flow rate, :math:`Q_S`.


    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`.

    """

    budget_filerecord = ListTemplateGenerator(("mvr", "options", "budget_filerecord"))
    budgetcsv_filerecord = ListTemplateGenerator(
        ("mvr", "options", "budgetcsv_filerecord")
    )
    packages = ListTemplateGenerator(("mvr", "packages", "packages"))
    perioddata = ListTemplateGenerator(("mvr", "period", "perioddata"))
    package_abbr = "mvr"
    _package_type = "mvr"
    dfn_file_name = "gwf-mvr.dfn"
    dfn = [
        ["header"],
        [
            "block options",
            "name print_input",
            "type keyword",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name print_flows",
            "type keyword",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name modelnames",
            "type keyword",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name budget_filerecord",
            "type record budget fileout budgetfile",
            "shape",
            "reader urword",
            "tagged true",
            "optional true",
        ],
        [
            "block options",
            "name budget",
            "type keyword",
            "shape",
            "in_record true",
            "reader urword",
            "tagged true",
            "optional false",
        ],
        [
            "block options",
            "name fileout",
            "type keyword",
            "shape",
            "in_record true",
            "reader urword",
            "tagged true",
            "optional false",
        ],
        [
            "block options",
            "name budgetfile",
            "type string",
            "preserve_case true",
            "shape",
            "in_record true",
            "reader urword",
            "tagged false",
            "optional false",
        ],
        [
            "block options",
            "name budgetcsv_filerecord",
            "type record budgetcsv fileout budgetcsvfile",
            "shape",
            "reader urword",
            "tagged true",
            "optional true",
        ],
        [
            "block options",
            "name budgetcsv",
            "type keyword",
            "shape",
            "in_record true",
            "reader urword",
            "tagged true",
            "optional false",
        ],
        [
            "block options",
            "name budgetcsvfile",
            "type string",
            "preserve_case true",
            "shape",
            "in_record true",
            "reader urword",
            "tagged false",
            "optional false",
        ],
        [
            "block dimensions",
            "name maxmvr",
            "type integer",
            "reader urword",
            "optional false",
        ],
        [
            "block dimensions",
            "name maxpackages",
            "type integer",
            "reader urword",
            "optional false",
        ],
        [
            "block packages",
            "name packages",
            "type recarray mname pname",
            "reader urword",
            "shape (npackages)",
            "optional false",
        ],
        [
            "block packages",
            "name mname",
            "type string",
            "reader urword",
            "shape",
            "tagged false",
            "in_record true",
            "optional true",
        ],
        [
            "block packages",
            "name pname",
            "type string",
            "reader urword",
            "shape",
            "tagged false",
            "in_record true",
            "optional false",
        ],
        [
            "block period",
            "name iper",
            "type integer",
            "block_variable true",
            "in_record true",
            "tagged false",
            "shape",
            "valid",
            "reader urword",
            "optional false",
        ],
        [
            "block period",
            "name perioddata",
            "type recarray mname1 pname1 id1 mname2 pname2 id2 mvrtype value",
            "shape (maxbound)",
            "reader urword",
        ],
        [
            "block period",
            "name mname1",
            "type string",
            "reader urword",
            "shape",
            "tagged false",
            "in_record true",
            "optional true",
        ],
        [
            "block period",
            "name pname1",
            "type string",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
        ],
        [
            "block period",
            "name id1",
            "type integer",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
            "numeric_index true",
        ],
        [
            "block period",
            "name mname2",
            "type string",
            "reader urword",
            "shape",
            "tagged false",
            "in_record true",
            "optional true",
        ],
        [
            "block period",
            "name pname2",
            "type string",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
        ],
        [
            "block period",
            "name id2",
            "type integer",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
            "numeric_index true",
        ],
        [
            "block period",
            "name mvrtype",
            "type string",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
        ],
        [
            "block period",
            "name value",
            "type double precision",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
        ],
    ]

    def __init__(
        self,
        parent_model_or_package,
        loading_package=False,
        print_input=None,
        print_flows=None,
        modelnames=None,
        budget_filerecord=None,
        budgetcsv_filerecord=None,
        maxmvr=None,
        maxpackages=None,
        packages=None,
        perioddata=None,
        filename=None,
        pname=None,
        **kwargs,
    ):
        """Initialize ModflowMvr."""
        super().__init__(
            parent=parent_model_or_package,
            package_type="mvr",
            filename=filename,
            pname=pname,
            loading_package=loading_package,
            **kwargs,
        )

        self.print_input = self.build_mfdata("print_input", print_input)
        self.print_flows = self.build_mfdata("print_flows", print_flows)
        self.modelnames = self.build_mfdata("modelnames", modelnames)
        self.budget_filerecord = self.build_mfdata(
            "budget_filerecord", budget_filerecord
        )
        self.budgetcsv_filerecord = self.build_mfdata(
            "budgetcsv_filerecord", budgetcsv_filerecord
        )
        self.maxmvr = self.build_mfdata("maxmvr", maxmvr)
        self.maxpackages = self.build_mfdata("maxpackages", maxpackages)
        self.packages = self.build_mfdata("packages", packages)
        self.perioddata = self.build_mfdata("perioddata", perioddata)

        self._init_complete = True


class MvrPackages(MFChildPackages):
    """
    MvrPackages is a container class for the ModflowMvr class.
    """

    package_abbr = "mvrpackages"

    def initialize(
        self,
        print_input=None,
        print_flows=None,
        modelnames=None,
        budget_filerecord=None,
        budgetcsv_filerecord=None,
        maxmvr=None,
        maxpackages=None,
        packages=None,
        perioddata=None,
        filename=None,
        pname=None,
    ):
        """
        Initialize a new ModflowMvr package, removing any sibling
        child packages attached to the same parent package.

        See :class:`ModflowMvr` for parameter definitions.
        """
        new_package = ModflowMvr(
            self._cpparent,
            print_input=print_input,
            print_flows=print_flows,
            modelnames=modelnames,
            budget_filerecord=budget_filerecord,
            budgetcsv_filerecord=budgetcsv_filerecord,
            maxmvr=maxmvr,
            maxpackages=maxpackages,
            packages=packages,
            perioddata=perioddata,
            filename=filename,
            pname=pname,
            child_builder_call=True,
        )
        self.init_package(new_package, filename)

    def append_package(
        self,
        print_input=None,
        print_flows=None,
        modelnames=None,
        budget_filerecord=None,
        budgetcsv_filerecord=None,
        maxmvr=None,
        maxpackages=None,
        packages=None,
        perioddata=None,
        filename=None,
        pname=None,
    ):
        """
        Add a new ModflowMvr package to the container.

        See :class:`ModflowMvr` for parameter definitions.
        """
        new_package = ModflowMvr(
            self._cpparent,
            print_input=print_input,
            print_flows=print_flows,
            modelnames=modelnames,
            budget_filerecord=budget_filerecord,
            budgetcsv_filerecord=budgetcsv_filerecord,
            maxmvr=maxmvr,
            maxpackages=maxpackages,
            packages=packages,
            perioddata=perioddata,
            filename=filename,
            pname=pname,
            child_builder_call=True,
        )
        self._append_package(new_package, filename)
