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

_DATABASECROSSSECTIONSET_CARD0 = (
    FieldSchema("csid", int, 0, 10, None),
    FieldSchema("title", str, 10, 70, None),
)

_DATABASECROSSSECTIONSET_CARD1 = (
    FieldSchema("nsid", int, 0, 10, 0),
    FieldSchema("hsid", int, 10, 10, 0),
    FieldSchema("bsid", int, 20, 10, 0),
    FieldSchema("ssid", int, 30, 10, 0),
    FieldSchema("tsid", int, 40, 10, 0),
    FieldSchema("dsid", int, 50, 10, 0),
    FieldSchema("id", int, 60, 10, None),
    FieldSchema("itype", int, 70, 10, 0),
)

class DatabaseCrossSectionSet(KeywordBase):
    """DYNA DATABASE_CROSS_SECTION_SET keyword"""

    keyword = "DATABASE"
    subkeyword = "CROSS_SECTION_SET"
    _link_fields = {
        "bsid": LinkType.SET_BEAM,
        "dsid": LinkType.SET_DISCRETE,
        "nsid": LinkType.SET_NODE,
        "hsid": LinkType.SET_SOLID,
    }

    def __init__(self, **kwargs):
        """Initialize the DatabaseCrossSectionSet class."""
        super().__init__(**kwargs)
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _DATABASECROSSSECTIONSET_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _DATABASECROSSSECTIONSET_CARD1,
                **kwargs,
            ),        ]
    @property
    def csid(self) -> typing.Optional[int]:
        """Get or set the Optional ID for cross section. If not specified cross section ID is taken to be the cross section order in the input deck.
        """ # nopep8
        return self._cards[0].get_value("csid")

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

    @property
    def title(self) -> typing.Optional[str]:
        """Get or set the Crowss section descriptor. It is suggested that unique descriptions be used.
        """ # nopep8
        return self._cards[0].get_value("title")

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

    @property
    def nsid(self) -> int:
        """Get or set the Nodal set ID, see *SET_NODE_option.
        """ # nopep8
        return self._cards[1].get_value("nsid")

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

    @property
    def hsid(self) -> int:
        """Get or set the Solid element set ID, see *SET_SOLID.
        """ # nopep8
        return self._cards[1].get_value("hsid")

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

    @property
    def bsid(self) -> int:
        """Get or set the Beam element set ID, see *SET_BEAM.
        """ # nopep8
        return self._cards[1].get_value("bsid")

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

    @property
    def ssid(self) -> int:
        """Get or set the Shell element set ID, see *SET_SHELL_option.
        """ # nopep8
        return self._cards[1].get_value("ssid")

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

    @property
    def tsid(self) -> int:
        """Get or set the Thick shell element set ID, see *SET_TSHELL.
        """ # nopep8
        return self._cards[1].get_value("tsid")

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

    @property
    def dsid(self) -> int:
        """Get or set the Discrete element set ID, see *SET_DISCRETE.
        """ # nopep8
        return self._cards[1].get_value("dsid")

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

    @property
    def id(self) -> typing.Optional[int]:
        """Get or set the Rigid body (see *MAT_RIGID, type 20) or accelerometer ID (see *ELEMENT_ SEATBELT_ACCELEROMETER). The force resultants are output in the updated local system of the rigid body or accelerometer.
        """ # nopep8
        return self._cards[1].get_value("id")

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

    @property
    def itype(self) -> int:
        """Get or set the Flag for local system type:
        EQ. 0: rigid body (default),
        EQ. 1: accelerometer.
        EQ. 2: coordinate ID.
        """ # nopep8
        return self._cards[1].get_value("itype")

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

    @property
    def bsid_link(self) -> typing.Optional[KeywordBase]:
        """Get the SET_BEAM_* keyword for bsid."""
        return self._get_set_link("BEAM", self.bsid)

    @bsid_link.setter
    def bsid_link(self, value: KeywordBase) -> None:
        """Set the SET_BEAM_* keyword for bsid."""
        self.bsid = value.sid

    @property
    def dsid_link(self) -> typing.Optional[KeywordBase]:
        """Get the SET_DISCRETE_* keyword for dsid."""
        return self._get_set_link("DISCRETE", self.dsid)

    @dsid_link.setter
    def dsid_link(self, value: KeywordBase) -> None:
        """Set the SET_DISCRETE_* keyword for dsid."""
        self.dsid = value.sid

    @property
    def nsid_link(self) -> typing.Optional[KeywordBase]:
        """Get the SET_NODE_* keyword for nsid."""
        return self._get_set_link("NODE", self.nsid)

    @nsid_link.setter
    def nsid_link(self, value: KeywordBase) -> None:
        """Set the SET_NODE_* keyword for nsid."""
        self.nsid = value.sid

    @property
    def hsid_link(self) -> typing.Optional[KeywordBase]:
        """Get the SET_SOLID_* keyword for hsid."""
        return self._get_set_link("SOLID", self.hsid)

    @hsid_link.setter
    def hsid_link(self, value: KeywordBase) -> None:
        """Set the SET_SOLID_* keyword for hsid."""
        self.hsid = value.sid

