# 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 MatAleHerschel 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

_MATALEHERSCHEL_CARD0 = (
    FieldSchema("mid", int, 0, 10, None),
    FieldSchema("ro", float, 10, 10, None),
    FieldSchema("pc", float, 20, 10, None),
    FieldSchema("mulo", float, 30, 10, None),
    FieldSchema("muhi", float, 40, 10, None),
    FieldSchema("rk", float, 50, 10, None),
    FieldSchema("unused", float, 60, 10, None),
    FieldSchema("rn", float, 70, 10, None),
)

_MATALEHERSCHEL_CARD1 = (
    FieldSchema("gdotc", float, 0, 10, None),
    FieldSchema("tao0", float, 10, 10, None),
)

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

class MatAleHerschel(KeywordBase):
    """DYNA MAT_ALE_HERSCHEL keyword"""

    keyword = "MAT"
    subkeyword = "ALE_HERSCHEL"
    option_specs = [
        OptionSpec("TITLE", -1, 1),
    ]

    def __init__(self, **kwargs):
        """Initialize the MatAleHerschel class."""
        super().__init__(**kwargs)
        kwargs["parent"] = self
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _MATALEHERSCHEL_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _MATALEHERSCHEL_CARD1,
                **kwargs,
            ),            OptionCardSet(
                option_spec = MatAleHerschel.option_specs[0],
                cards = [
                    Card.from_field_schemas_with_defaults(
                        _MATALEHERSCHEL_OPTION0_CARD0,
                        **kwargs,
                    ),
                ],
                **kwargs
            ),
        ]
    @property
    def mid(self) -> typing.Optional[int]:
        """Get or set the Material identification. A unique number or label must be specified.
        """ # 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 ro(self) -> typing.Optional[float]:
        """Get or set the Mass density.
        """ # nopep8
        return self._cards[0].get_value("ro")

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

    @property
    def pc(self) -> typing.Optional[float]:
        """Get or set the Pressure cutoff (<=0.0).
        """ # nopep8
        return self._cards[0].get_value("pc")

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

    @property
    def mulo(self) -> typing.Optional[float]:
        """Get or set the There are 4 possible cases:
        1.  If MULO = 0.0, then inviscid fluid is assumed.
        2.  If MULO > 0.0, and MUHI = 0.0 or is not defined, then this is the traditional constant dynamic viscosity coefficient μ.
        3.  If MULO > 0.0, and MUHI > 0.0, then MULO and MUHI are lower and upper viscosity limit values for a power-law-like variable viscosity model.
        4.  If MULO is negative (for example, MULO = -1), then a user input data load curve (with LCID = 1) defining dynamic
        viscosity as a function of equivalent strain rate is used.
        """ # nopep8
        return self._cards[0].get_value("mulo")

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

    @property
    def muhi(self) -> typing.Optional[float]:
        """Get or set the Upper dynamic viscosity limit (default = 0.0). This is defined only if RK and RN are defined for the variable viscosity case
        """ # nopep8
        return self._cards[0].get_value("muhi")

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

    @property
    def rk(self) -> typing.Optional[float]:
        """Get or set the consistency factor
        """ # nopep8
        return self._cards[0].get_value("rk")

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

    @property
    def rn(self) -> typing.Optional[float]:
        """Get or set the power law index
        """ # nopep8
        return self._cards[0].get_value("rn")

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

    @property
    def gdotc(self) -> typing.Optional[float]:
        """Get or set the critical shear strain rate.
        """ # nopep8
        return self._cards[1].get_value("gdotc")

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

    @property
    def tao0(self) -> typing.Optional[float]:
        """Get or set the yield stress.
        """ # nopep8
        return self._cards[1].get_value("tao0")

    @tao0.setter
    def tao0(self, value: float) -> None:
        """Set the tao0 property."""
        self._cards[1].set_value("tao0", 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")

