# 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 AleSmoothing 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.keyword_base import KeywordBase
from ansys.dyna.core.lib.keyword_base import LinkType
from ansys.dyna.core.keywords.keyword_classes.auto.node.node import Node

_ALESMOOTHING_CARD0 = (
    FieldSchema("dnid", int, 0, 10, None),
    FieldSchema("nid1", int, 10, 10, None),
    FieldSchema("nid2", int, 20, 10, None),
    FieldSchema("ipre", int, 30, 10, 0),
    FieldSchema("xco", float, 40, 10, 0.0),
    FieldSchema("yco", float, 50, 10, 0.0),
    FieldSchema("zco", float, 60, 10, 0.0),
)

class AleSmoothing(KeywordBase):
    """DYNA ALE_SMOOTHING keyword"""

    keyword = "ALE"
    subkeyword = "SMOOTHING"
    _link_fields = {
        "dnid": LinkType.NODE,
        "nid1": LinkType.NODE,
        "nid2": LinkType.NODE,
    }

    def __init__(self, **kwargs):
        """Initialize the AleSmoothing class."""
        super().__init__(**kwargs)
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _ALESMOOTHING_CARD0,
                **kwargs,
            ),        ]
    @property
    def dnid(self) -> typing.Optional[int]:
        """Get or set the Dependent node or node set ID:
        GT.0: DNID is an ALE node.
        EQ.0 : The dependent nodes are the nodes of an ALE mesh connected to the nodes in INID1.See Remark 2
        LT.0: -DNID is the ID of an ALE node set.See Remark 2
        """ # nopep8
        return self._cards[0].get_value("dnid")

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

    @property
    def nid1(self) -> typing.Optional[int]:
        """Get or set the ID of first node or set for constraining the dependent nodes:
        GT.0: NID1 is a node.
        LT.0 : -NID1 is a segment set ID if XCO = YCO = ZCO = 0.0.
        Otherwise, -NID1 is a node set ID.See Remark 2
        """ # nopep8
        return self._cards[0].get_value("nid1")

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

    @property
    def nid2(self) -> typing.Optional[int]:
        """Get or set the ID of second node or node set for constraining the dependent nodes:
        GT.0 : NID2 is a node.
        EQ.0 : The dependent node motion is solely controlled by
        NID1.See Remarks 2 and 3.
        LT.0 : -NID2 is a node set ID.See Remark 2.
        """ # nopep8
        return self._cards[0].get_value("nid2")

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

    @property
    def ipre(self) -> int:
        """Get or set the EQ.0: smoothing constraints are performed after mesh relaxation,
        EQ.1: Smoothing constraints are performed before mesh relaxation.
        """ # nopep8
        return self._cards[0].get_value("ipre")

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

    @property
    def xco(self) -> float:
        """Get or set the x-coordinate of constraint vector.
        """ # nopep8
        return self._cards[0].get_value("xco")

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

    @property
    def yco(self) -> float:
        """Get or set the y-coordinate of constraint vector.
        """ # nopep8
        return self._cards[0].get_value("yco")

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

    @property
    def zco(self) -> float:
        """Get or set the z-coordinate of constraint vector.
        """ # nopep8
        return self._cards[0].get_value("zco")

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

    @property
    def dnid_link(self) -> typing.Optional[KeywordBase]:
        """Get the NODE keyword containing the given dnid."""
        return self._get_link_by_attr("NODE", "nid", self.dnid, "parts")

    @property
    def nid1_link(self) -> typing.Optional[KeywordBase]:
        """Get the NODE keyword containing the given nid1."""
        return self._get_link_by_attr("NODE", "nid", self.nid1, "parts")

    @property
    def nid2_link(self) -> typing.Optional[KeywordBase]:
        """Get the NODE keyword containing the given nid2."""
        return self._get_link_by_attr("NODE", "nid", self.nid2, "parts")

