# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Module providing the MatAddPoreAir class."""
import typing
from ansys.dyna.core.lib.card import Card, Field, Flag
from ansys.dyna.core.lib.field_schema import FieldSchema
from ansys.dyna.core.lib.option_card import OptionCardSet, OptionSpec
from ansys.dyna.core.lib.keyword_base import KeywordBase
from ansys.dyna.core.lib.keyword_base import LinkType
from ansys.dyna.core.keywords.keyword_classes.auto.define.define_curve import DefineCurve

_MATADDPOREAIR_CARD0 = (
    FieldSchema("mid", int, 0, 10, None),
    FieldSchema("pa_rho", float, 10, 10, None),
    FieldSchema("pa_pre", float, 20, 10, None),
    FieldSchema("pore", float, 30, 10, 1.0),
    FieldSchema("dvimin", float, 40, 10, None),
)

_MATADDPOREAIR_CARD1 = (
    FieldSchema("perm1", float, 0, 10, 0.0),
    FieldSchema("perm2", float, 10, 10, None),
    FieldSchema("perm3", float, 20, 10, None),
    FieldSchema("cdarcy", float, 30, 10, 1.0),
    FieldSchema("cdf", float, 40, 10, 0.0),
    FieldSchema("lcpgd1", int, 50, 10, 0),
    FieldSchema("lcpgd2", int, 60, 10, None),
    FieldSchema("lcpgd3", int, 70, 10, None),
)

_MATADDPOREAIR_OPTION0_CARD0 = (
    FieldSchema("title", str, 0, 80, None),
)

class MatAddPoreAir(KeywordBase):
    """DYNA MAT_ADD_PORE_AIR keyword"""

    keyword = "MAT"
    subkeyword = "ADD_PORE_AIR"
    option_specs = [
        OptionSpec("TITLE", -1, 1),
    ]
    _link_fields = {
        "mid": LinkType.MAT,
        "lcpgd1": LinkType.DEFINE_CURVE,
        "lcpgd2": LinkType.DEFINE_CURVE,
        "lcpgd3": LinkType.DEFINE_CURVE,
    }

    def __init__(self, **kwargs):
        """Initialize the MatAddPoreAir class."""
        super().__init__(**kwargs)
        kwargs["parent"] = self
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _MATADDPOREAIR_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _MATADDPOREAIR_CARD1,
                **kwargs,
            ),            OptionCardSet(
                option_spec = MatAddPoreAir.option_specs[0],
                cards = [
                    Card.from_field_schemas_with_defaults(
                        _MATADDPOREAIR_OPTION0_CARD0,
                        **kwargs,
                    ),
                ],
                **kwargs
            ),
        ]
    @property
    def mid(self) -> typing.Optional[int]:
        """Get or set the Material identification - must be same as the structural material.
        """ # nopep8
        return self._cards[0].get_value("mid")

    @mid.setter
    def mid(self, value: int) -> None:
        """Set the mid property."""
        self._cards[0].set_value("mid", value)

    @property
    def pa_rho(self) -> typing.Optional[float]:
        """Get or set the Initial density of pore air, default to atmospheric air density, AIR_RO, defined in *CONTROL_PORE_AIR
        """ # nopep8
        return self._cards[0].get_value("pa_rho")

    @pa_rho.setter
    def pa_rho(self, value: float) -> None:
        """Set the pa_rho property."""
        self._cards[0].set_value("pa_rho", value)

    @property
    def pa_pre(self) -> typing.Optional[float]:
        """Get or set the Initial pressure of pore air, default to atmospheric air pressure, AIR_P, defined in *CONTROL_PORE_AIR.
        """ # nopep8
        return self._cards[0].get_value("pa_pre")

    @pa_pre.setter
    def pa_pre(self, value: float) -> None:
        """Set the pa_pre property."""
        self._cards[0].set_value("pa_pre", value)

    @property
    def pore(self) -> float:
        """Get or set the Porosity, ratio of pores to total volume, default to 1.
        """ # nopep8
        return self._cards[0].get_value("pore")

    @pore.setter
    def pore(self, value: float) -> None:
        """Set the pore property."""
        self._cards[0].set_value("pore", value)

    @property
    def dvimin(self) -> typing.Optional[float]:
        """Get or set the Optional parameters to trigger air flow analysis.  Pore air flow analysis is performed only for these nodes having incremental volume change ratio, abs(V(t)-V(t-dt))/V(t-dt), larger than DVMIN, where V(t) is the nodal volume at time=t.  This parameter may be needed for the material that has very high permeability.  Caution has to be exercised when using DVMIN, a reasonable starting value may equal the inverse of the total number of analysis time steps.  Another option to control pore air analysis can be found in *SENSOR_CONTROL.
        """ # nopep8
        return self._cards[0].get_value("dvimin")

    @dvimin.setter
    def dvimin(self, value: float) -> None:
        """Set the dvimin property."""
        self._cards[0].set_value("dvimin", value)

    @property
    def perm1(self) -> float:
        """Get or set the Permeability of pore air along x-direction, <0 when ABS(PERMX) is the curve defining permeability coefficient as a function of volume ratio,	current-volume)/volume-at-stress-free-state.
        """ # nopep8
        return self._cards[1].get_value("perm1")

    @perm1.setter
    def perm1(self, value: float) -> None:
        """Set the perm1 property."""
        self._cards[1].set_value("perm1", value)

    @property
    def perm2(self) -> typing.Optional[float]:
        """Get or set the Permeability of pore air along y-direction, <0 when ABS(PERMY) is the curve defining permeability coefficient as a function of volume ratio,	current-volume)/volume-at-stress-free-state
        """ # nopep8
        return self._cards[1].get_value("perm2")

    @perm2.setter
    def perm2(self, value: float) -> None:
        """Set the perm2 property."""
        self._cards[1].set_value("perm2", value)

    @property
    def perm3(self) -> typing.Optional[float]:
        """Get or set the Permeability of pore air along z-direction, <0 when ABS(PERMZ) is the curve defining permeability coefficient as a function of volume ratio,	current-volume)/volume-at-stress-free-state.
        """ # nopep8
        return self._cards[1].get_value("perm3")

    @perm3.setter
    def perm3(self, value: float) -> None:
        """Set the perm3 property."""
        self._cards[1].set_value("perm3", value)

    @property
    def cdarcy(self) -> float:
        """Get or set the Coefficient of Darcy's law
        """ # nopep8
        return self._cards[1].get_value("cdarcy")

    @cdarcy.setter
    def cdarcy(self, value: float) -> None:
        """Set the cdarcy property."""
        self._cards[1].set_value("cdarcy", value)

    @property
    def cdf(self) -> float:
        """Get or set the Coefficient of Dupuit-Forchheimer law
        """ # nopep8
        return self._cards[1].get_value("cdf")

    @cdf.setter
    def cdf(self, value: float) -> None:
        """Set the cdf property."""
        self._cards[1].set_value("cdf", value)

    @property
    def lcpgd1(self) -> int:
        """Get or set the Curves defining non-linear Darcy's laws along x, y and z-directions
        """ # nopep8
        return self._cards[1].get_value("lcpgd1")

    @lcpgd1.setter
    def lcpgd1(self, value: int) -> None:
        """Set the lcpgd1 property."""
        self._cards[1].set_value("lcpgd1", value)

    @property
    def lcpgd2(self) -> typing.Optional[int]:
        """Get or set the Curves defining non-linear Darcy's laws along x, y and z-directions
        """ # nopep8
        return self._cards[1].get_value("lcpgd2")

    @lcpgd2.setter
    def lcpgd2(self, value: int) -> None:
        """Set the lcpgd2 property."""
        self._cards[1].set_value("lcpgd2", value)

    @property
    def lcpgd3(self) -> typing.Optional[int]:
        """Get or set the Curves defining non-linear Darcy's laws along x, y and z-directions
        """ # nopep8
        return self._cards[1].get_value("lcpgd3")

    @lcpgd3.setter
    def lcpgd3(self, value: int) -> None:
        """Set the lcpgd3 property."""
        self._cards[1].set_value("lcpgd3", value)

    @property
    def title(self) -> typing.Optional[str]:
        """Get or set the Additional title line
        """ # nopep8
        return self._cards[2].cards[0].get_value("title")

    @title.setter
    def title(self, value: str) -> None:
        """Set the title property."""
        self._cards[2].cards[0].set_value("title", value)

        if value:
            self.activate_option("TITLE")

    @property
    def mid_link(self) -> typing.Optional[KeywordBase]:
        """Get the MAT_* keyword for mid."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_type("MAT"):
            if kwd.mid == self.mid:
                return kwd
        return None

    @mid_link.setter
    def mid_link(self, value: KeywordBase) -> None:
        """Set the MAT_* keyword for mid."""
        self.mid = value.mid

    @property
    def lcpgd1_link(self) -> typing.Optional[DefineCurve]:
        """Get the DefineCurve object for lcpgd1."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_full_type("DEFINE", "CURVE"):
            if kwd.lcid == self.lcpgd1:
                return kwd
        return None

    @lcpgd1_link.setter
    def lcpgd1_link(self, value: DefineCurve) -> None:
        """Set the DefineCurve object for lcpgd1."""
        self.lcpgd1 = value.lcid

    @property
    def lcpgd2_link(self) -> typing.Optional[DefineCurve]:
        """Get the DefineCurve object for lcpgd2."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_full_type("DEFINE", "CURVE"):
            if kwd.lcid == self.lcpgd2:
                return kwd
        return None

    @lcpgd2_link.setter
    def lcpgd2_link(self, value: DefineCurve) -> None:
        """Set the DefineCurve object for lcpgd2."""
        self.lcpgd2 = value.lcid

    @property
    def lcpgd3_link(self) -> typing.Optional[DefineCurve]:
        """Get the DefineCurve object for lcpgd3."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_full_type("DEFINE", "CURVE"):
            if kwd.lcid == self.lcpgd3:
                return kwd
        return None

    @lcpgd3_link.setter
    def lcpgd3_link(self, value: DefineCurve) -> None:
        """Set the DefineCurve object for lcpgd3."""
        self.lcpgd3 = value.lcid

