# 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 PartCompositeTshell 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.hourglass.hourglass import Hourglass

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

_PARTCOMPOSITETSHELL_CARD1 = (
    FieldSchema("pid", int, 0, 10, None),
    FieldSchema("elform", int, 10, 10, 1),
    FieldSchema("shrf", float, 20, 10, 1.0),
    FieldSchema("unused", float, 30, 10, None),
    FieldSchema("unused", float, 40, 10, None),
    FieldSchema("hgid", int, 50, 10, 0),
    FieldSchema("unused", int, 60, 10, None),
    FieldSchema("tshear", int, 70, 10, 0),
)

_PARTCOMPOSITETSHELL_CARD2 = (
    FieldSchema("mid1", int, 0, 10, None),
    FieldSchema("thick1", float, 10, 10, None),
    FieldSchema("b1", float, 20, 10, None),
    FieldSchema("tmid1", int, 30, 10, None),
    FieldSchema("mid2", int, 40, 10, None),
    FieldSchema("thick2", float, 50, 10, None),
    FieldSchema("b2", float, 60, 10, None),
    FieldSchema("tmid2", int, 70, 10, None),
)

class PartCompositeTshell(KeywordBase):
    """DYNA PART_COMPOSITE_TSHELL keyword"""

    keyword = "PART"
    subkeyword = "COMPOSITE_TSHELL"
    _link_fields = {
        "mid1": LinkType.MAT,
        "mid2": LinkType.MAT,
        "hgid": LinkType.HOURGLASS,
    }

    def __init__(self, **kwargs):
        """Initialize the PartCompositeTshell class."""
        super().__init__(**kwargs)
        self._cards = [
            Card.from_field_schemas_with_defaults(
                _PARTCOMPOSITETSHELL_CARD0,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _PARTCOMPOSITETSHELL_CARD1,
                **kwargs,
            ),            Card.from_field_schemas_with_defaults(
                _PARTCOMPOSITETSHELL_CARD2,
                **kwargs,
            ),        ]
    @property
    def title(self) -> typing.Optional[str]:
        """Get or set the Heading for the part.
        """ # 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 pid(self) -> typing.Optional[int]:
        """Get or set the Part ID.
        """ # nopep8
        return self._cards[1].get_value("pid")

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

    @property
    def elform(self) -> int:
        """Get or set the Element formulation:
        EQ.1: one point reduced integration (default),
        EQ.2: selective reduced 2x2 in plane integration.
        EQ.3: assumed strain 2x2 in plane integration.
        EQ.5:  assumed strain reduced integration.
        """ # nopep8
        return self._cards[1].get_value("elform")

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

    @property
    def shrf(self) -> float:
        """Get or set the Shear correction factor which scales the transverse shear stress.  The shell formulations in LS-DYNA, with the exception of the BCIZ and DK elements, are based on a first order shear deformation theory that yields constant transverse shear strains which violates the condition of zero traction on the top and bottom surfaces of the shell.  The shear correction factor is attempt to compensate for this error.
        """ # nopep8
        return self._cards[1].get_value("shrf")

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

    @property
    def hgid(self) -> int:
        """Get or set the Hourglass/bulk viscosity identification defined in the *HOURGLASS Section:
        EQ.0:  default values are used..
        """ # nopep8
        return self._cards[1].get_value("hgid")

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

    @property
    def tshear(self) -> int:
        """Get or set the Flag for transverse shear strain distribution (see remarks 3 and 4):
        EQ.0: Parabolic,
        EQ.1: Constant through thickness
        """ # nopep8
        return self._cards[1].get_value("tshear")

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

    @property
    def mid1(self) -> typing.Optional[int]:
        """Get or set the Material ID of integration point i, see *MAT_? Section
        """ # nopep8
        return self._cards[2].get_value("mid1")

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

    @property
    def thick1(self) -> typing.Optional[float]:
        """Get or set the Thickness of integration point .
        """ # nopep8
        return self._cards[2].get_value("thick1")

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

    @property
    def b1(self) -> typing.Optional[float]:
        """Get or set the Material angle of integration point i.
        """ # nopep8
        return self._cards[2].get_value("b1")

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

    @property
    def tmid1(self) -> typing.Optional[int]:
        """Get or set the Thermal ID
        """ # nopep8
        return self._cards[2].get_value("tmid1")

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

    @property
    def mid2(self) -> typing.Optional[int]:
        """Get or set the Material ID of integration point i, see *MAT_? Section
        """ # nopep8
        return self._cards[2].get_value("mid2")

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

    @property
    def thick2(self) -> typing.Optional[float]:
        """Get or set the Thickness of integration point
        """ # nopep8
        return self._cards[2].get_value("thick2")

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

    @property
    def b2(self) -> typing.Optional[float]:
        """Get or set the Material angle of integration point i
        """ # nopep8
        return self._cards[2].get_value("b2")

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

    @property
    def tmid2(self) -> typing.Optional[int]:
        """Get or set the Thermal ID
        """ # nopep8
        return self._cards[2].get_value("tmid2")

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

    @property
    def mid1_link(self) -> typing.Optional[KeywordBase]:
        """Get the MAT_* keyword for mid1."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_type("MAT"):
            if kwd.mid == self.mid1:
                return kwd
        return None

    @mid1_link.setter
    def mid1_link(self, value: KeywordBase) -> None:
        """Set the MAT_* keyword for mid1."""
        self.mid1 = value.mid

    @property
    def mid2_link(self) -> typing.Optional[KeywordBase]:
        """Get the MAT_* keyword for mid2."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_type("MAT"):
            if kwd.mid == self.mid2:
                return kwd
        return None

    @mid2_link.setter
    def mid2_link(self, value: KeywordBase) -> None:
        """Set the MAT_* keyword for mid2."""
        self.mid2 = value.mid

    @property
    def hgid_link(self) -> typing.Optional[Hourglass]:
        """Get the Hourglass object for hgid."""
        if self.deck is None:
            return None
        for kwd in self.deck.get_kwds_by_full_type("HOURGLASS", "HOURGLASS"):
            if kwd.hgid == self.hgid:
                return kwd
        return None

    @hgid_link.setter
    def hgid_link(self, value: Hourglass) -> None:
        """Set the Hourglass object for hgid."""
        self.hgid = value.hgid

