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

_DEFINESTOCHASTICVARIATION_CARD0 = (
    FieldSchema("id_sv", int, 0, 10, None),
    FieldSchema("pid", int, 10, 10, None),
    FieldSchema("pid_typ", int, 20, 10, 0),
    FieldSchema("icor", int, 30, 10, 0),
    FieldSchema("var_s", int, 40, 10, 0),
    FieldSchema("var_f", int, 50, 10, 0),
    FieldSchema("irng", int, 60, 10, 0),
)

_DEFINESTOCHASTICVARIATION_CARD1 = (
    FieldSchema("r1", float, 0, 10, None),
    FieldSchema("r2", float, 10, 10, None),
    FieldSchema("r3", float, 20, 10, None),
)

_DEFINESTOCHASTICVARIATION_CARD2 = (
    FieldSchema("lcid", int, 0, 10, None),
)

_DEFINESTOCHASTICVARIATION_CARD3 = (
    FieldSchema("r1", float, 0, 10, None),
    FieldSchema("r2", float, 10, 10, None),
    FieldSchema("r3", float, 20, 10, None),
)

_DEFINESTOCHASTICVARIATION_CARD4 = (
    FieldSchema("lcid", int, 0, 10, None),
)

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

class DefineStochasticVariation(KeywordBase):
    """DYNA DEFINE_STOCHASTIC_VARIATION keyword"""

    keyword = "DEFINE"
    subkeyword = "STOCHASTIC_VARIATION"
    option_specs = [
        OptionSpec("TITLE", -1, 1),
    ]
    _link_fields = {
        "lcid": LinkType.DEFINE_CURVE,
        "lcid": LinkType.DEFINE_CURVE,
    }

    def __init__(self, **kwargs):
        """Initialize the DefineStochasticVariation class."""
        super().__init__(**kwargs)
        kwargs["parent"] = self
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _DEFINESTOCHASTICVARIATION_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _DEFINESTOCHASTICVARIATION_CARD1,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _DEFINESTOCHASTICVARIATION_CARD2,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _DEFINESTOCHASTICVARIATION_CARD3,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _DEFINESTOCHASTICVARIATION_CARD4,
                **kwargs,
            ),            OptionCardSet(
                option_spec = DefineStochasticVariation.option_specs[0],
                cards = [
                    Card.from_field_schemas_with_defaults(
                        _DEFINESTOCHASTICVARIATION_OPTION0_CARD0,
                        **kwargs,
                    ),
                ],
                **kwargs
            ),
        ]
    @property
    def id_sv(self) -> typing.Optional[int]:
        """Get or set the Stochastic variation ID. A unique ID number must be used
        """ # nopep8
        return self._cards[0].get_value("id_sv")

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

    @property
    def pid(self) -> typing.Optional[int]:
        """Get or set the *PART ID or *SET_PART ID
        """ # nopep8
        return self._cards[0].get_value("pid")

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

    @property
    def pid_typ(self) -> int:
        """Get or set the Flag for PID type. If PID and PID_TYP are both 0, then the
        properties defined here apply to all shell and solid parts using
        materials with the STOCHASTIC option.
        EQ.0: PID is a *PART ID.
        EQ.1: PID is a *SET_PART ID
        """ # nopep8
        return self._cards[0].get_value("pid_typ")

    @pid_typ.setter
    def pid_typ(self, value: int) -> None:
        """Set the pid_typ property."""
        if value not in [0, 1, None]:
            raise Exception("""pid_typ must be `None` or one of {0,1}.""")
        self._cards[0].set_value("pid_typ", value)

    @property
    def icor(self) -> int:
        """Get or set the Correlation between the yield stress and failure strain scaling.
        EQ.0: Perfect correlation.
        EQ.1: No correlation. The yield stress and failure strain are independently scaled.
        """ # nopep8
        return self._cards[0].get_value("icor")

    @icor.setter
    def icor(self, value: int) -> None:
        """Set the icor property."""
        if value not in [0, 1, None]:
            raise Exception("""icor must be `None` or one of {0,1}.""")
        self._cards[0].set_value("icor", value)

    @property
    def var_s(self) -> int:
        """Get or set the Variation type for scaling the yield stress.
        EQ.0: The scale factor is 1.0 everywhere.
        EQ.1: The scale factor is random number in the uniform random distribution in the interval defined by R1 and R2.
        EQ.2: The scale factor is a random number obeying the Gaussian distribution defined by R1, R2, and R3.
        EQ.3: The scale factor is defined by the probability distribution function defined by curve LCID.
        EQ.4: The scale factor is defined by the cumulative distribution function defined by curve LCID.
        """ # nopep8
        return self._cards[0].get_value("var_s")

    @var_s.setter
    def var_s(self, value: int) -> None:
        """Set the var_s property."""
        if value not in [0, 1, 2, 3, 4, None]:
            raise Exception("""var_s must be `None` or one of {0,1,2,3,4}.""")
        self._cards[0].set_value("var_s", value)

    @property
    def var_f(self) -> int:
        """Get or set the Variation type for scaling failure strain.
        EQ.0: The scale factor is 1.0 everywhere.
        EQ.1: The scale factor is random number in the uniform random distribution in the interval defined by R1 and R2.
        EQ.2: The scale factor is a random number obeying the Gaussian distribution defined by R1, R2, and R3.
        EQ.3: The scale factor is defined by the probability distribution function defined by curve LCID.
        EQ.4: The scale factor is defined by the cumulative distribution function defined by curve LCID.
        """ # nopep8
        return self._cards[0].get_value("var_f")

    @var_f.setter
    def var_f(self, value: int) -> None:
        """Set the var_f property."""
        if value not in [0, 1, 2, 3, 4, None]:
            raise Exception("""var_f must be `None` or one of {0,1,2,3,4}.""")
        self._cards[0].set_value("var_f", value)

    @property
    def irng(self) -> int:
        """Get or set the Flag for random number generation.
        EQ.0:	Use deterministic(pseudo - ) random number generator.The same input always leads to the same distribution.
        EQ.1 : Use non - deterministic(true) random number generator.With the same input, a different distribution is achieved in each run
        """ # nopep8
        return self._cards[0].get_value("irng")

    @irng.setter
    def irng(self, value: int) -> None:
        """Set the irng property."""
        if value not in [0, 1, None]:
            raise Exception("""irng must be `None` or one of {0,1}.""")
        self._cards[0].set_value("irng", value)

    @property
    def r1(self) -> typing.Optional[float]:
        """Get or set the Real values to define the stochastic distribution
        """ # nopep8
        return self._cards[1].get_value("r1")

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

    @property
    def r2(self) -> typing.Optional[float]:
        """Get or set the Real values to define the stochastic distribution
        """ # nopep8
        return self._cards[1].get_value("r2")

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

    @property
    def r3(self) -> typing.Optional[float]:
        """Get or set the Real values to define the stochastic distribution
        """ # nopep8
        return self._cards[1].get_value("r3")

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

    @property
    def lcid(self) -> typing.Optional[int]:
        """Get or set the Curve ID defining the stochastic distribution
        """ # nopep8
        return self._cards[2].get_value("lcid")

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

    @property
    def r1(self) -> typing.Optional[float]:
        """Get or set the Real values to define the stochastic distribution
        """ # nopep8
        return self._cards[3].get_value("r1")

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

    @property
    def r2(self) -> typing.Optional[float]:
        """Get or set the Real values to define the stochastic distribution
        """ # nopep8
        return self._cards[3].get_value("r2")

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

    @property
    def r3(self) -> typing.Optional[float]:
        """Get or set the Real values to define the stochastic distribution
        """ # nopep8
        return self._cards[3].get_value("r3")

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

    @property
    def lcid(self) -> typing.Optional[int]:
        """Get or set the Curve ID defining the stochastic distribution
        """ # nopep8
        return self._cards[4].get_value("lcid")

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

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

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

        if value:
            self.activate_option("TITLE")

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

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

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

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

