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

_DATABASEFSISENSOR_CARD0 = (
    FieldSchema("dtout", float, 0, 10, None),
    FieldSchema("binary", int, 10, 10, 1),
)

_DATABASEFSISENSOR_CARD1 = (
    FieldSchema("dbfsi_id", int, 0, 10, None),
    FieldSchema("nid", int, 10, 10, None),
    FieldSchema("segmid", int, 20, 10, None),
    FieldSchema("offset", float, 30, 10, None),
    FieldSchema("nd1", int, 40, 10, None),
    FieldSchema("nd2", int, 50, 10, None),
    FieldSchema("nd3", int, 60, 10, None),
)

class DatabaseFsiSensor(KeywordBase):
    """DYNA DATABASE_FSI_SENSOR keyword"""

    keyword = "DATABASE"
    subkeyword = "FSI_SENSOR"
    _link_fields = {
        "nid": LinkType.NODE,
        "nd1": LinkType.NODE,
        "nd2": LinkType.NODE,
        "nd3": LinkType.NODE,
        "segmid": LinkType.ELEMENT_SHELL,
    }

    def __init__(self, **kwargs):
        """Initialize the DatabaseFsiSensor class."""
        super().__init__(**kwargs)
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _DATABASEFSISENSOR_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _DATABASEFSISENSOR_CARD1,
                **kwargs,
            ),        ]
    @property
    def dtout(self) -> typing.Optional[float]:
        """Get or set the Output interval
        """ # nopep8
        return self._cards[0].get_value("dtout")

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

    @property
    def binary(self) -> int:
        """Get or set the Flag for binary output.  See remarks under "Output Files and Post-Processing" in Appendix O, "LS-DYNA MPP User Guide."
        EQ.1:	ASCII file is written:	This is the default for shared memory parallel (SMP) LS-DYNA executables.
        EQ.2:	Data written to a binary database binout, which contains data that would otherwise be output to the ASCII file.
        The ASCII file in this case is not created.  This is the default for MPP LS-DYNA executables.
        EQ.3:	ASCII file is written, and the data is also written to the binary database (NOTE: MPP LS-DYNA executables will only produce the binary database).
        """ # nopep8
        return self._cards[0].get_value("binary")

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

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

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

    @property
    def nid(self) -> typing.Optional[int]:
        """Get or set the Node ID,If NID=0 or blank, the sensor will be placed in the center of a four-sided segment defined by SEGMID.
        """ # nopep8
        return self._cards[1].get_value("nid")

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

    @property
    def segmid(self) -> typing.Optional[int]:
        """Get or set the SegmentID (Lagrangian shell element ID) associated with the above node ID.
        """ # nopep8
        return self._cards[1].get_value("segmid")

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

    @property
    def offset(self) -> typing.Optional[float]:
        """Get or set the Offset distance between the pressure sensor and the Lagrangian segment surface.  If it is positive, it is on the side pointed to by the segment normal vector.
        """ # nopep8
        return self._cards[1].get_value("offset")

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

    @property
    def nd1(self) -> typing.Optional[int]:
        """Get or set the Nodes defining the solid face for the solid element in the three-dimensional model
        or shell side for the shell element in the two-dimensional model, from which the sensor is located.
        In three dimensions, if the solid face has 4 nodes, only the diagonal opposites ND1 and ND2 are required.
        If the solid face is triangular, a third node ND3 should be provided. In two dimensions, only ND1 and ND2 are required to define the shell side
        """ # nopep8
        return self._cards[1].get_value("nd1")

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

    @property
    def nd2(self) -> typing.Optional[int]:
        """Get or set the Nodes defining the solid face for the solid element in the three-dimensional model
        or shell side for the shell element in the two-dimensional model, from which the sensor is located.
        In three dimensions, if the solid face has 4 nodes, only the diagonal opposites ND1 and ND2 are required.
        If the solid face is triangular, a third node ND3 should be provided. In two dimensions, only ND1 and ND2 are required to define the shell side
        """ # nopep8
        return self._cards[1].get_value("nd2")

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

    @property
    def nd3(self) -> typing.Optional[int]:
        """Get or set the Nodes defining the solid face for the solid element in the three-dimensional model
        or shell side for the shell element in the two-dimensional model, from which the sensor is located.
        In three dimensions, if the solid face has 4 nodes, only the diagonal opposites ND1 and ND2 are required.
        If the solid face is triangular, a third node ND3 should be provided. In two dimensions, only ND1 and ND2 are required to define the shell side
        """ # nopep8
        return self._cards[1].get_value("nd3")

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

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

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

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

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

    @property
    def segmid_link(self) -> typing.Optional[KeywordBase]:
        """Get the ELEMENT keyword containing the given segmid."""
        return self._get_link_by_attr("ELEMENT", "eid", self.segmid, "parts")

