/* file: simultaneous_constraint_group.swift 	 generated: Mon Jan  3 16:32:52 2022 */

/* This file was generated by the EXPRESS to Swift translator "exp2swift", 
    derived from STEPcode (formerly NIST's SCL).
 exp2swift version: v.1.0.1, derived from stepcode v0.8 as of 2019/11/23 
 WARNING: You probably don't want to edit it since your modifications 
    will be lost if exp2swift is used to regenerate it.
 */

 
import SwiftSDAIcore

extension AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF {
//MARK: -ENTITY DEFINITION in EXPRESS
/*

  ENTITY simultaneous_constraint_group
    SUBTYPE OF ( variational_representation_item );
      constraint_group  : SET [2 : ?] OF constraint_group_member;
    WHERE
      wr1: ( SIZEOF( QUERY ( q <* using_representations( SELF ) | ( SIZEOF( QUERY ( r <* q.items | ( ( 
               'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.SIMULTANEOUS_CONSTRAINT_GROUP'  IN TYPEOF( r ) ) 
               AND ( SIZEOF( QUERY ( s <* constraint_group | ( ( s IN r\simultaneous_constraint_group.
               constraint_group ) AND ( NOT ( r :=: SELF ) ) ) ) ) > 0 ) ) ) ) > 0 ) ) ) = 0 );
      wr2: ( SIZEOF( QUERY ( q <* using_representations( constraint_group[1] ) | ( SIZEOF( QUERY ( r <* 
               constraint_group | item_in_context( r, q.context_of_items ) ) ) = SIZEOF( constraint_group ) ) ) ) 
               > 0 );
      wr3: ( SIZEOF( QUERY ( q <* constraint_group | ( ( 'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.'
               + 'EXPLICIT_CONSTRAINT'  IN TYPEOF( q ) ) AND ( SIZEOF( QUERY ( r <* q.constrained_elements | 
               ( SIZEOF( QUERY ( s <* constraint_group | ( r IN s.reference_elements ) ) ) > 0 ) ) ) > 0 ) ) ) ) 
               = 0 );
  END_ENTITY; -- simultaneous_constraint_group (line:29426 file:ap242ed2_mim_lf_v1.101.TY.exp)

*/


//MARK: - ALL DEFINED ATTRIBUTES
/*
  SUPER- ENTITY(1)	representation_item
    ATTR:  name,	TYPE: label -- EXPLICIT


  SUPER- ENTITY(2)	variational_representation_item
    (no local attributes)

  ENTITY(SELF)	simultaneous_constraint_group
    ATTR:  constraint_group,	TYPE: SET [2 : ?] OF constraint_group_member -- EXPLICIT


*/


//MARK: - Partial Entity
  public final class _simultaneous_constraint_group : SDAI.PartialEntity {
    public override class var entityReferenceType: SDAI.EntityReference.Type {
      eSIMULTANEOUS_CONSTRAINT_GROUP.self
    }

    //ATTRIBUTES
    /// EXPLICIT ATTRIBUTE 
    public internal(set) var _constraint_group: SDAI.SET<sCONSTRAINT_GROUP_MEMBER>/*[2:nil]*/  // PLAIN EXPLICIT ATTRIBUTE

    public override var typeMembers: Set<SDAI.STRING> {
      var members = Set<SDAI.STRING>()
      members.insert(SDAI.STRING(Self.typeName))
      //SELECT data types (indirectly) referencing the current type as a member of the select list
      members.insert(SDAI.STRING(sCONSTRAINT_GROUP_MEMBER.typeName)) // -> Self
      return members
    }


    //VALUE COMPARISON SUPPORT
    public override func hashAsValue(into hasher: inout Hasher, visited complexEntities: inout Set<SDAI.ComplexEntity>) {
      super.hashAsValue(into: &hasher, visited: &complexEntities)
      self._constraint_group.value.hashAsValue(into: &hasher, visited: &complexEntities)
    }

    public override func isValueEqual(to rhs: SDAI.PartialEntity, visited comppairs: inout Set<SDAI.ComplexPair>) -> Bool {
      guard let rhs = rhs as? Self else { return false }
      if !super.isValueEqual(to: rhs, visited: &comppairs) { return false }
      if let comp = self._constraint_group.value.isValueEqualOptionally(to: rhs._constraint_group.value, visited: &comppairs)	{
        if !comp { return false }
      }
      else { return false }
      return true
    }

    public override func isValueEqualOptionally(to rhs: SDAI.PartialEntity, visited comppairs: inout Set<SDAI.ComplexPair>) -> Bool? {
      guard let rhs = rhs as? Self else { return false }
      var result: Bool? = true
      if let comp = super.isValueEqualOptionally(to: rhs, visited: &comppairs) {
        if !comp { return false }
      }
      else { result = nil }
      if let comp = self._constraint_group.value.isValueEqualOptionally(to: rhs._constraint_group.value, visited: &comppairs) {
        if !comp { return false }
      }
      else { result = nil }
      return result
    }


    //MARK: WHERE RULES (ENTITY)
    public static func WHERE_wr1(SELF: eSIMULTANEOUS_CONSTRAINT_GROUP?) -> SDAI.LOGICAL {
      guard let SELF = SELF else { return SDAI.UNKNOWN }

      let _TEMP1 = USING_REPRESENTATIONS(sFOUNDED_ITEM_SELECT(/*eSIMULTANEOUS_CONSTRAINT_GROUP*/SELF))
      let _TEMP2 = _TEMP1?.QUERY{ Q in 

          let _TEMP1 = Q.ITEMS
          let _TEMP2 = _TEMP1.QUERY{ R in 

              let _TEMP1 = SDAI.TYPEOF(R, IS: eSIMULTANEOUS_CONSTRAINT_GROUP.self)
              let _TEMP2 = SELF.CONSTRAINT_GROUP
                .QUERY{ S in 

                  let _TEMP1 = R.GROUP_REF(eSIMULTANEOUS_CONSTRAINT_GROUP.self)
                  let _TEMP2 = _TEMP1?.CONSTRAINT_GROUP
                  let _TEMP3 = SDAI.aggregate(_TEMP2, contains: S)
                  let _TEMP4 = SDAI.FORCE_OPTIONAL(R) .===. SDAI.FORCE_OPTIONAL(SELF)
                  let _TEMP5 =  !_TEMP4
                  let _TEMP6 = _TEMP3 && _TEMP5
                  return _TEMP6 }
              let _TEMP3 = SDAI.SIZEOF(_TEMP2)
              let _TEMP4 = _TEMP3 > SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
              let _TEMP5 = _TEMP1 && _TEMP4
              return _TEMP5 }
          let _TEMP3 = SDAI.SIZEOF(_TEMP2)
          let _TEMP4 = _TEMP3 > SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
          return _TEMP4 }
      let _TEMP3 = SDAI.SIZEOF(_TEMP2)
      let _TEMP4 = _TEMP3 .==. SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
      return _TEMP4
    }
    public static func WHERE_wr2(SELF: eSIMULTANEOUS_CONSTRAINT_GROUP?) -> SDAI.LOGICAL {
      guard let SELF = SELF else { return SDAI.UNKNOWN }

      let _TEMP1 = SELF.CONSTRAINT_GROUP[1]
      let _TEMP2 = USING_REPRESENTATIONS(sFOUNDED_ITEM_SELECT(/*sCONSTRAINT_GROUP_MEMBER*/_TEMP1))
      let _TEMP3 = _TEMP2?.QUERY{ Q in 

          let _TEMP1 = SELF.CONSTRAINT_GROUP
            .QUERY{ R in 

              let _TEMP1 = Q.CONTEXT_OF_ITEMS
              let _TEMP2 = ITEM_IN_CONTEXT(
                ITEM: eREPRESENTATION_ITEM(/*sCONSTRAINT_GROUP_MEMBER*/R), 
                CNTXT: _TEMP1)
              return SDAI.LOGICAL(/*SDAI.BOOLEAN*/_TEMP2) }
          let _TEMP2 = SDAI.SIZEOF(_TEMP1)
          let _TEMP3 = SDAI.SIZEOF(SELF.CONSTRAINT_GROUP)
          let _TEMP4 = _TEMP2 .==. _TEMP3
          return _TEMP4 }
      let _TEMP4 = SDAI.SIZEOF(_TEMP3)
      let _TEMP5 = _TEMP4 > SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
      return _TEMP5
    }
    public static func WHERE_wr3(SELF: eSIMULTANEOUS_CONSTRAINT_GROUP?) -> SDAI.LOGICAL {
      guard let SELF = SELF else { return SDAI.UNKNOWN }

      let _TEMP1 = SELF.CONSTRAINT_GROUP
        .QUERY{ Q in 

          let _TEMP1 = SDAI.TYPEOF(Q, IS: eEXPLICIT_CONSTRAINT.self)
          let _TEMP2 = /*runtime*/Q.CONSTRAINED_ELEMENTS
          let _TEMP3 = /*runtime*/_TEMP2?
            .QUERY{ R in 

              let _TEMP1 = SELF.CONSTRAINT_GROUP
                .QUERY{ S in 

                  let _TEMP1 = /*runtime*/S.REFERENCE_ELEMENTS
                  let _TEMP2 = SDAI.aggregate(_TEMP1, contains: /*runtime*/R)
                  return _TEMP2 }
              let _TEMP2 = SDAI.SIZEOF(_TEMP1)
              let _TEMP3 = _TEMP2 > SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
              return _TEMP3 }
          let _TEMP4 = SDAI.SIZEOF(SDAI.AGGREGATE<SDAI.GENERIC>(/*runtime*/_TEMP3))
          let _TEMP5 = _TEMP4 > SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
          let _TEMP6 = _TEMP1 && _TEMP5
          return _TEMP6 }
      let _TEMP2 = SDAI.SIZEOF(_TEMP1)
      let _TEMP3 = _TEMP2 .==. SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
      return _TEMP3
    }

    //EXPRESS IMPLICIT PARTIAL ENTITY CONSTRUCTOR
    public init(CONSTRAINT_GROUP: SDAI.SET<sCONSTRAINT_GROUP_MEMBER>/*[2:nil]*/ ) {
      self._constraint_group = CONSTRAINT_GROUP
      super.init(asAbstructSuperclass:())

    }

    //p21 PARTIAL ENTITY CONSTRUCTOR
    public required convenience init?(parameters: [P21Decode.ExchangeStructure.Parameter], exchangeStructure: P21Decode.ExchangeStructure) {
      let numParams = 1
      guard parameters.count == numParams
      else { exchangeStructure.error = "number of p21 parameters(\(parameters.count)) are different from expected(\(numParams)) for entity(\(Self.entityName)) constructor"; return nil }

      guard case .success(let p0) = exchangeStructure.recoverRequiredParameter(as: SDAI.SET<
        sCONSTRAINT_GROUP_MEMBER>.self, from: parameters[0])
      else { exchangeStructure.add(errorContext: "while recovering parameter #0 for entity(\(Self.entityName)) constructor"); return nil }

      self.init( CONSTRAINT_GROUP: p0 )
    }
  }


//MARK: - Entity Reference

/** ENTITY reference
- EXPRESS:
```express
  ENTITY simultaneous_constraint_group
    SUBTYPE OF ( variational_representation_item );
      constraint_group  : SET [2 : ?] OF constraint_group_member;
    WHERE
      wr1: ( SIZEOF( QUERY ( q <* using_representations( SELF ) | ( SIZEOF( QUERY ( r <* q.items | ( ( 
               'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.SIMULTANEOUS_CONSTRAINT_GROUP'  IN TYPEOF( r ) ) 
               AND ( SIZEOF( QUERY ( s <* constraint_group | ( ( s IN r\simultaneous_constraint_group.
               constraint_group ) AND ( NOT ( r :=: SELF ) ) ) ) ) > 0 ) ) ) ) > 0 ) ) ) = 0 );
      wr2: ( SIZEOF( QUERY ( q <* using_representations( constraint_group[1] ) | ( SIZEOF( QUERY ( r <* 
               constraint_group | item_in_context( r, q.context_of_items ) ) ) = SIZEOF( constraint_group ) ) ) ) 
               > 0 );
      wr3: ( SIZEOF( QUERY ( q <* constraint_group | ( ( 'AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.'
               + 'EXPLICIT_CONSTRAINT'  IN TYPEOF( q ) ) AND ( SIZEOF( QUERY ( r <* q.constrained_elements | 
               ( SIZEOF( QUERY ( s <* constraint_group | ( r IN s.reference_elements ) ) ) > 0 ) ) ) > 0 ) ) ) ) 
               = 0 );
  END_ENTITY; -- simultaneous_constraint_group (line:29426 file:ap242ed2_mim_lf_v1.101.TY.exp)

```
*/
  public final class eSIMULTANEOUS_CONSTRAINT_GROUP : SDAI.EntityReference {

    //MARK: PARTIAL ENTITY
    public override class var partialEntityType: SDAI.PartialEntity.Type {
      _simultaneous_constraint_group.self
    }
    public let partialEntity: _simultaneous_constraint_group

    //MARK: SUPERTYPES
    public let super_eREPRESENTATION_ITEM: eREPRESENTATION_ITEM 	// [1]
    public let super_eVARIATIONAL_REPRESENTATION_ITEM: eVARIATIONAL_REPRESENTATION_ITEM 	// [2]
    public var super_eSIMULTANEOUS_CONSTRAINT_GROUP: eSIMULTANEOUS_CONSTRAINT_GROUP { return self } 	// [3]

    //MARK: SUBTYPES

    //MARK: ATTRIBUTES
    /// __EXPLICIT__ attribute
    /// - origin: SELF( ``eSIMULTANEOUS_CONSTRAINT_GROUP`` )
    public var CONSTRAINT_GROUP: SDAI.SET<sCONSTRAINT_GROUP_MEMBER>/*[2:nil]*/  {
      get {
        return SDAI.UNWRAP( self.partialEntity._constraint_group )
      }
      set(newValue) {
        let partial = self.partialEntity
        partial._constraint_group = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUPER( ``eREPRESENTATION_ITEM`` )
    public var NAME: tLABEL {
      get {
        return SDAI.UNWRAP( super_eREPRESENTATION_ITEM.partialEntity._name )
      }
      set(newValue) {
        let partial = super_eREPRESENTATION_ITEM.partialEntity
        partial._name = SDAI.UNWRAP(newValue)
      }
    }


    //MARK: INITIALIZERS
    public convenience init?(_ entityRef: SDAI.EntityReference?) {
      let complex = entityRef?.complexEntity
      self.init(complex: complex)
    }

    public required init?(complex complexEntity: SDAI.ComplexEntity?) {
      guard let partial = complexEntity?.partialEntityInstance(_simultaneous_constraint_group.self) else { return nil }
      self.partialEntity = partial

      guard let super1 = complexEntity?.entityReference(eREPRESENTATION_ITEM.self) else { return nil }
      self.super_eREPRESENTATION_ITEM = super1

      guard let super2 = complexEntity?.entityReference(eVARIATIONAL_REPRESENTATION_ITEM.self) else { return nil }
      self.super_eVARIATIONAL_REPRESENTATION_ITEM = super2

      super.init(complex: complexEntity)
    }

    public required convenience init?<G: SDAIGenericType>(fromGeneric generic: G?) {
      guard let entityRef = generic?.entityReference else { return nil }
      self.init(complex: entityRef.complexEntity)
    }

    public convenience init?<S: SDAISelectType>(_ select: S?) { self.init(possiblyFrom: select) }
    public convenience init?(_ complex: SDAI.ComplexEntity?) { self.init(complex: complex) }


    //MARK: WHERE RULE VALIDATION (ENTITY)
    public override class func validateWhereRules(instance:SDAI.EntityReference?, prefix:SDAI.WhereLabel) -> [SDAI.WhereLabel:SDAI.LOGICAL] {
      guard let instance = instance as? Self else { return [:] }

      let prefix2 = prefix + " \(instance)"

      var result = super.validateWhereRules(instance:instance, prefix:prefix2)
      result[prefix2 + " .WHERE_wr1"] = _simultaneous_constraint_group.WHERE_wr1(SELF: instance)
      result[prefix2 + " .WHERE_wr2"] = _simultaneous_constraint_group.WHERE_wr2(SELF: instance)
      result[prefix2 + " .WHERE_wr3"] = _simultaneous_constraint_group.WHERE_wr3(SELF: instance)
      return result
    }


    //MARK: DICTIONARY DEFINITION
    public class override var entityDefinition: SDAIDictionarySchema.EntityDefinition { _entityDefinition }
    private static let _entityDefinition: SDAIDictionarySchema.EntityDefinition = createEntityDefinition()

    private static func createEntityDefinition() -> SDAIDictionarySchema.EntityDefinition {
      let entityDef = SDAIDictionarySchema.EntityDefinition(name: "SIMULTANEOUS_CONSTRAINT_GROUP", type: self, explicitAttributeCount: 1)

      //MARK: SUPERTYPE REGISTRATIONS
      entityDef.add(supertype: eREPRESENTATION_ITEM.self)
      entityDef.add(supertype: eVARIATIONAL_REPRESENTATION_ITEM.self)
      entityDef.add(supertype: eSIMULTANEOUS_CONSTRAINT_GROUP.self)

      //MARK: ATTRIBUTE REGISTRATIONS
      entityDef.addAttribute(name: "CONSTRAINT_GROUP", keyPath: \eSIMULTANEOUS_CONSTRAINT_GROUP.CONSTRAINT_GROUP, 
        kind: .explicit, source: .thisEntity, mayYieldEntityReference: true)
      entityDef.addAttribute(name: "NAME", keyPath: \eSIMULTANEOUS_CONSTRAINT_GROUP.NAME, 
        kind: .explicit, source: .superEntity, mayYieldEntityReference: false)

      return entityDef
    }

  }
}
