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

_DEFINESPOTWELDFAILURERESULTANTS_CARD0 = (
    FieldSchema("id", int, 0, 10, 0),
    FieldSchema("dsn", float, 10, 10, 0.0),
    FieldSchema("dss", float, 20, 10, 0.0),
    FieldSchema("dlcidsn", int, 30, 10, 0),
    FieldSchema("dlcidss", int, 40, 10, 0),
)

_DEFINESPOTWELDFAILURERESULTANTS_CARD1 = (
    FieldSchema("pid_i", int, 0, 10, None),
    FieldSchema("pid_j", int, 10, 10, None),
    FieldSchema("snij", float, 20, 10, 0.0),
    FieldSchema("ssij", float, 30, 10, 0.0),
    FieldSchema("lcidsnij", int, 40, 10, 0),
    FieldSchema("lcidssij", int, 50, 10, 0),
)

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

class DefineSpotweldFailureResultants(KeywordBase):
    """DYNA DEFINE_SPOTWELD_FAILURE_RESULTANTS keyword"""

    keyword = "DEFINE"
    subkeyword = "SPOTWELD_FAILURE_RESULTANTS"
    option_specs = [
        OptionSpec("TITLE", -1, 1),
    ]
    _link_fields = {
        "dlcidsn": LinkType.DEFINE_CURVE,
        "dlcidss": LinkType.DEFINE_CURVE,
        "lcidsnij": LinkType.DEFINE_CURVE,
        "lcidssij": LinkType.DEFINE_CURVE,
        "pid_i": LinkType.PART,
        "pid_j": LinkType.PART,
    }

    def __init__(self, **kwargs):
        """Initialize the DefineSpotweldFailureResultants class."""
        super().__init__(**kwargs)
        kwargs["parent"] = self
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _DEFINESPOTWELDFAILURERESULTANTS_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _DEFINESPOTWELDFAILURERESULTANTS_CARD1,
                **kwargs,
            ),            OptionCardSet(
                option_spec = DefineSpotweldFailureResultants.option_specs[0],
                cards = [
                    Card.from_field_schemas_with_defaults(
                        _DEFINESPOTWELDFAILURERESULTANTS_OPTION0_CARD0,
                        **kwargs,
                    ),
                ],
                **kwargs
            ),
        ]
    @property
    def id(self) -> int:
        """Get or set the Identification number. Only one table is allowed
        """ # nopep8
        return self._cards[0].get_value("id")

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

    @property
    def dsn(self) -> float:
        """Get or set the Default value of the normal static stress resultant at failure
        """ # nopep8
        return self._cards[0].get_value("dsn")

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

    @property
    def dss(self) -> float:
        """Get or set the Default value of the transverse static stress resultant at failure
        """ # nopep8
        return self._cards[0].get_value("dss")

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

    @property
    def dlcidsn(self) -> int:
        """Get or set the Load curve ID defining a scale factor for the normal stress resultant as a function of strain rate. This factor multiplies DSN to obtain the failure value at a given strain rate.
        """ # nopep8
        return self._cards[0].get_value("dlcidsn")

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

    @property
    def dlcidss(self) -> int:
        """Get or set the Load curve ID defining a scale factor for the static shear stress resultant as a function of strain rate. This factor multiplies DSS to obtain the failure value at a given strain rate.
        """ # nopep8
        return self._cards[0].get_value("dlcidss")

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

    @property
    def pid_i(self) -> typing.Optional[int]:
        """Get or set the Part ID I.
        """ # nopep8
        return self._cards[1].get_value("pid_i")

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

    @property
    def pid_j(self) -> typing.Optional[int]:
        """Get or set the Part ID J.
        """ # nopep8
        return self._cards[1].get_value("pid_j")

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

    @property
    def snij(self) -> float:
        """Get or set the The normal static stress resultant at failure between parts I and J.
        """ # nopep8
        return self._cards[1].get_value("snij")

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

    @property
    def ssij(self) -> float:
        """Get or set the The transverse shear static stress resultant at failure between parts I and J.
        """ # nopep8
        return self._cards[1].get_value("ssij")

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

    @property
    def lcidsnij(self) -> int:
        """Get or set the Load curve ID defining a scale factor for the normal stress resultant as a function of strain rate. This factor multiplies SNIJ to obtain the failure value at a given strain rate.
        """ # nopep8
        return self._cards[1].get_value("lcidsnij")

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

    @property
    def lcidssij(self) -> int:
        """Get or set the Load curve ID defining a scale factor for static shear stress resultant as a function of strain rate. This factor multiplies SSIJ to obtain the failure value at a given strain rate.
        """ # nopep8
        return self._cards[1].get_value("lcidssij")

    @lcidssij.setter
    def lcidssij(self, value: int) -> None:
        """Set the lcidssij property."""
        self._cards[1].set_value("lcidssij", 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 dlcidsn_link(self) -> typing.Optional[DefineCurve]:
        """Get the DefineCurve object for dlcidsn."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_full_type("DEFINE", "CURVE"):
            if kwd.lcid == self.dlcidsn:
                return kwd
        return None

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

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

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

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

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

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

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

    @property
    def pid_i_link(self) -> typing.Optional[KeywordBase]:
        """Get the PART keyword containing the given pid_i."""
        return self._get_link_by_attr("PART", "pid", self.pid_i, "parts")

    @property
    def pid_j_link(self) -> typing.Optional[KeywordBase]:
        """Get the PART keyword containing the given pid_j."""
        return self._get_link_by_attr("PART", "pid", self.pid_j, "parts")

