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

_CONTROLFORMINGSTONING_CARD0 = (
    FieldSchema("istone", int, 0, 10, None),
    FieldSchema("length", float, 10, 10, None),
    FieldSchema("width", int, 20, 10, None),
    FieldSchema("step", float, 30, 10, 0.5),
    FieldSchema("direction", int, 40, 10, None),
    FieldSchema("reverse", int, 50, 10, 0),
    FieldSchema("method", int, 60, 10, 0),
)

_CONTROLFORMINGSTONING_CARD1 = (
    FieldSchema("node1", int, 0, 10, None),
    FieldSchema("node2", int, 10, 10, None),
    FieldSchema("setid", int, 20, 10, None),
    FieldSchema("itype", int, 30, 10, 1),
)

class ControlFormingStoning(KeywordBase):
    """DYNA CONTROL_FORMING_STONING keyword"""

    keyword = "CONTROL"
    subkeyword = "FORMING_STONING"
    _link_fields = {
        "node1": LinkType.NODE,
        "node2": LinkType.NODE,
    }

    def __init__(self, **kwargs):
        """Initialize the ControlFormingStoning class."""
        super().__init__(**kwargs)
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _CONTROLFORMINGSTONING_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _CONTROLFORMINGSTONING_CARD1,
                **kwargs,
            ),        ]
    @property
    def istone(self) -> typing.Optional[int]:
        """Get or set the activate this capability.
        """ # nopep8
        return self._cards[0].get_value("istone")

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

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

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

    @property
    def width(self) -> typing.Optional[int]:
        """Get or set the Width of the stone
        """ # nopep8
        return self._cards[0].get_value("width")

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

    @property
    def step(self) -> float:
        """Get or set the The step size for the stone to move in each step
        """ # nopep8
        return self._cards[0].get_value("step")

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

    @property
    def direction(self) -> typing.Optional[int]:
        """Get or set the Number of automatically determined stoning direction(s).
        """ # nopep8
        return self._cards[0].get_value("direction")

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

    @property
    def reverse(self) -> int:
        """Get or set the Surface normal reversing option.
        EQ.0: do not reverse surface normals.
        EQ.1: reverse surface normals
        """ # nopep8
        return self._cards[0].get_value("reverse")

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

    @property
    def method(self) -> int:
        """Get or set the Stoning method.
        EQ.0: curvature-based method.
        """ # nopep8
        return self._cards[0].get_value("method")

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

    @property
    def node1(self) -> typing.Optional[int]:
        """Get or set the Node1 and Node2 define the orientation of the stone
        """ # nopep8
        return self._cards[1].get_value("node1")

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

    @property
    def node2(self) -> typing.Optional[int]:
        """Get or set the Node1 and Node2 define the orientation of the stone.
        """ # nopep8
        return self._cards[1].get_value("node2")

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

    @property
    def setid(self) -> typing.Optional[int]:
        """Get or set the id, itype 1: node set, itype 2: shell set
        """ # nopep8
        return self._cards[1].get_value("setid")

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

    @property
    def itype(self) -> int:
        """Get or set the 1:node set, 2 shell set
        """ # nopep8
        return self._cards[1].get_value("itype")

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

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

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

