/* file: styled_tessellated_item_with_colours.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 styled_tessellated_item_with_colours
    SUBTYPE OF ( styled_item );
      SELF\styled_item.item  : tessellated_surface_item;
      colour_type            : colour_type_enum;
      colour_values          : LIST [1 : ?] OF LIST [3 : 4] OF unsigned_8_bit_integer;
    DERIVE
      coloured_coordinate_values  : coordinates_list := get_coordinate_values( item );
    WHERE
      wr1: ( SIZEOF( SELF\styled_item.styles ) = 0 );
      wr2: ( ( ( colour_type = rgb8 ) AND ( SIZEOF( QUERY ( clist <* colour_values | ( NOT ( SIZEOF( clist ) 
               = 3 ) ) ) ) = 0 ) ) OR ( ( colour_type = rgbt8 ) AND ( SIZEOF( QUERY ( clist <* colour_values
               | ( NOT ( SIZEOF( clist ) = 4 ) ) ) ) = 0 ) ) );
      wr3: ( SIZEOF( colour_values ) = coloured_coordinate_values\coordinates_list.npoints );
  END_ENTITY; -- styled_tessellated_item_with_colours (line:31010 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)	styled_item
    ATTR:  styles,	TYPE: SET [0 : ?] OF presentation_style_assignment -- EXPLICIT

    ATTR:  item,	TYPE: styled_item_target -- EXPLICIT
      -- possibly overriden by
          ENTITY: tessellated_annotation_occurrence,	TYPE: tessellated_geometric_set
          ENTITY: annotation_placeholder_occurrence,	TYPE: geometric_set
          ENTITY: annotation_symbol_occurrence,	TYPE: annotation_symbol_occurrence_item
          ENTITY: annotation_curve_occurrence,	TYPE: curve_or_curve_set
      *** ENTITY: styled_tessellated_item_with_colours,	TYPE: tessellated_surface_item
          ENTITY: annotation_text_occurrence,	TYPE: annotation_text_occurrence_item
          ENTITY: hidden_element_over_riding_styled_item,	TYPE: camera_image
          ENTITY: annotation_fill_area_occurrence,	TYPE: annotation_fill_area
          ENTITY: annotation_point_occurrence,	TYPE: point
          ENTITY: annotation_plane,	TYPE: plane_or_planar_box


  ENTITY(SELF)	styled_tessellated_item_with_colours
    REDCR: item,	TYPE: tessellated_surface_item -- EXPLICIT
      -- OVERRIDING ENTITY: styled_item

    ATTR:  colour_type,	TYPE: colour_type_enum -- EXPLICIT

    ATTR:  colour_values,	TYPE: LIST [1 : ?] OF LIST [3 : 4] OF unsigned_8_bit_integer -- EXPLICIT

    ATTR:  coloured_coordinate_values,	TYPE: coordinates_list -- DERIVED
      := get_coordinate_values( item )


*/


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

    //ATTRIBUTES
    /* override var _item: sTESSELLATED_SURFACE_ITEM	//EXPLICIT REDEFINITION(eSTYLED_ITEM) */

    /// EXPLICIT ATTRIBUTE 
    public internal(set) var _colour_type: nCOLOUR_TYPE_ENUM // PLAIN EXPLICIT ATTRIBUTE

    /// EXPLICIT ATTRIBUTE 
    public internal(set) var _colour_values: SDAI.LIST<SDAI.LIST<tUNSIGNED_8_BIT_INTEGER>/*[3:4]*/ >/*[1:nil]*/  // PLAIN EXPLICIT ATTRIBUTE

    /// DERIVE ATTRIBUTE
    internal func _coloured_coordinate_values__getter(SELF: eSTYLED_TESSELLATED_ITEM_WITH_COLOURS) -> 
      eCOORDINATES_LIST?  {

      let _TEMP1 = GET_COORDINATE_VALUES(SELF.ITEM)
      return _TEMP1
    }

    public override var typeMembers: Set<SDAI.STRING> {
      var members = Set<SDAI.STRING>()
      members.insert(SDAI.STRING(Self.typeName))
      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._colour_type.value.hashAsValue(into: &hasher, visited: &complexEntities)
      self._colour_values.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._colour_type.value.isValueEqualOptionally(to: rhs._colour_type.value, visited: &comppairs)	{
        if !comp { return false }
      }
      else { return false }
      if let comp = self._colour_values.value.isValueEqualOptionally(to: rhs._colour_values.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._colour_type.value.isValueEqualOptionally(to: rhs._colour_type.value, visited: &comppairs) {
        if !comp { return false }
      }
      else { result = nil }
      if let comp = self._colour_values.value.isValueEqualOptionally(to: rhs._colour_values.value, visited: &comppairs) {
        if !comp { return false }
      }
      else { result = nil }
      return result
    }


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

      let _TEMP1 = SELF.GROUP_REF(eSTYLED_ITEM.self)
      let _TEMP2 = _TEMP1?.STYLES
      let _TEMP3 = SDAI.SIZEOF(_TEMP2)
      let _TEMP4 = _TEMP3 .==. SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
      return _TEMP4
    }
    public static func WHERE_wr2(SELF: eSTYLED_TESSELLATED_ITEM_WITH_COLOURS?) -> SDAI.LOGICAL {
      guard let SELF = SELF else { return SDAI.UNKNOWN }

      let _TEMP1 = SDAI.FORCE_OPTIONAL(SELF.COLOUR_TYPE) .==. SDAI.FORCE_OPTIONAL(RGB8)
      let _TEMP2 = SELF.COLOUR_VALUES
        .QUERY{ CLIST in 

          let _TEMP1 = SDAI.SIZEOF(CLIST)
          let _TEMP2 = _TEMP1 .==. SDAI.FORCE_OPTIONAL(SDAI.INTEGER(3))
          let _TEMP3 =  !_TEMP2
          return _TEMP3 }
      let _TEMP3 = SDAI.SIZEOF(_TEMP2)
      let _TEMP4 = _TEMP3 .==. SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
      let _TEMP5 = _TEMP1 && _TEMP4
      let _TEMP6 = SDAI.FORCE_OPTIONAL(SELF.COLOUR_TYPE) .==. SDAI.FORCE_OPTIONAL(RGBT8)
      let _TEMP7 = SELF.COLOUR_VALUES
        .QUERY{ CLIST in 

          let _TEMP1 = SDAI.SIZEOF(CLIST)
          let _TEMP2 = _TEMP1 .==. SDAI.FORCE_OPTIONAL(SDAI.INTEGER(4))
          let _TEMP3 =  !_TEMP2
          return _TEMP3 }
      let _TEMP8 = SDAI.SIZEOF(_TEMP7)
      let _TEMP9 = _TEMP8 .==. SDAI.FORCE_OPTIONAL(SDAI.INTEGER(0))
      let _TEMP10 = _TEMP6 && _TEMP9
      let _TEMP11 = _TEMP5 || _TEMP10
      return _TEMP11
    }
    public static func WHERE_wr3(SELF: eSTYLED_TESSELLATED_ITEM_WITH_COLOURS?) -> SDAI.LOGICAL {
      guard let SELF = SELF else { return SDAI.UNKNOWN }

      let _TEMP1 = SDAI.SIZEOF(SELF.COLOUR_VALUES)
      let _TEMP2 = SELF.COLOURED_COORDINATE_VALUES?.GROUP_REF(eCOORDINATES_LIST.self)
      let _TEMP3 = _TEMP2?.NPOINTS
      let _TEMP4 = _TEMP1 .==. _TEMP3
      return _TEMP4
    }

    //EXPRESS IMPLICIT PARTIAL ENTITY CONSTRUCTOR
    public init(COLOUR_TYPE: nCOLOUR_TYPE_ENUM, COLOUR_VALUES: SDAI.LIST<SDAI.LIST<tUNSIGNED_8_BIT_INTEGER>
                /*[3:4]*/ >/*[1:nil]*/ ) {
      self._colour_type = COLOUR_TYPE
      self._colour_values = COLOUR_VALUES
      super.init(asAbstructSuperclass:())

    }

    //p21 PARTIAL ENTITY CONSTRUCTOR
    public required convenience init?(parameters: [P21Decode.ExchangeStructure.Parameter], exchangeStructure: P21Decode.ExchangeStructure) {
      let numParams = 2
      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: nCOLOUR_TYPE_ENUM.self, from: parameters[0])
      else { exchangeStructure.add(errorContext: "while recovering parameter #0 for entity(\(Self.entityName)) constructor"); return nil }

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

      self.init( COLOUR_TYPE: p0, COLOUR_VALUES: p1 )
    }
  }


//MARK: - Entity Reference

/** ENTITY reference
- EXPRESS:
```express
  ENTITY styled_tessellated_item_with_colours
    SUBTYPE OF ( styled_item );
      SELF\styled_item.item  : tessellated_surface_item;
      colour_type            : colour_type_enum;
      colour_values          : LIST [1 : ?] OF LIST [3 : 4] OF unsigned_8_bit_integer;
    DERIVE
      coloured_coordinate_values  : coordinates_list := get_coordinate_values( item );
    WHERE
      wr1: ( SIZEOF( SELF\styled_item.styles ) = 0 );
      wr2: ( ( ( colour_type = rgb8 ) AND ( SIZEOF( QUERY ( clist <* colour_values | ( NOT ( SIZEOF( clist ) 
               = 3 ) ) ) ) = 0 ) ) OR ( ( colour_type = rgbt8 ) AND ( SIZEOF( QUERY ( clist <* colour_values
               | ( NOT ( SIZEOF( clist ) = 4 ) ) ) ) = 0 ) ) );
      wr3: ( SIZEOF( colour_values ) = coloured_coordinate_values\coordinates_list.npoints );
  END_ENTITY; -- styled_tessellated_item_with_colours (line:31010 file:ap242ed2_mim_lf_v1.101.TY.exp)

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

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

    //MARK: SUPERTYPES
    public let super_eREPRESENTATION_ITEM: eREPRESENTATION_ITEM 	// [1]
    public let super_eSTYLED_ITEM: eSTYLED_ITEM 	// [2]
    public var super_eSTYLED_TESSELLATED_ITEM_WITH_COLOURS: eSTYLED_TESSELLATED_ITEM_WITH_COLOURS { return self } 	// [3]

    //MARK: SUBTYPES

    //MARK: ATTRIBUTES
    /// __EXPLICIT REDEF__ attribute
    /// - origin: SELF( ``eSTYLED_TESSELLATED_ITEM_WITH_COLOURS`` )
    public var ITEM: sTESSELLATED_SURFACE_ITEM {
      get {
        return SDAI.UNWRAP( sTESSELLATED_SURFACE_ITEM( super_eSTYLED_ITEM.partialEntity._item ) )
      }
      set(newValue) {
        let partial = super_eSTYLED_ITEM.partialEntity
        partial._item = SDAI.UNWRAP(
          sSTYLED_ITEM_TARGET(newValue))
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SELF( ``eSTYLED_TESSELLATED_ITEM_WITH_COLOURS`` )
    public var COLOUR_TYPE: nCOLOUR_TYPE_ENUM {
      get {
        return SDAI.UNWRAP( self.partialEntity._colour_type )
      }
      set(newValue) {
        let partial = self.partialEntity
        partial._colour_type = SDAI.UNWRAP(newValue)
      }
    }

    /// __DERIVE__ attribute
    /// - origin: SELF( ``eSTYLED_TESSELLATED_ITEM_WITH_COLOURS`` )
    public var COLOURED_COORDINATE_VALUES: eCOORDINATES_LIST?  {
      get {
        if let cached = cachedValue(derivedAttributeName:"COLOURED_COORDINATE_VALUES") {
          return cached.value as! eCOORDINATES_LIST? 
        }
        let origin = self
        let value = origin.partialEntity._coloured_coordinate_values__getter(SELF: origin)
        updateCache(derivedAttributeName:"COLOURED_COORDINATE_VALUES", value:value)
        return value
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SUPER( ``eSTYLED_ITEM`` )
    public var STYLES: SDAI.SET<ePRESENTATION_STYLE_ASSIGNMENT>/*[0:nil]*/  {
      get {
        return SDAI.UNWRAP( super_eSTYLED_ITEM.partialEntity._styles )
      }
      set(newValue) {
        let partial = super_eSTYLED_ITEM.partialEntity
        partial._styles = SDAI.UNWRAP(newValue)
      }
    }

    /// __EXPLICIT__ attribute
    /// - origin: SELF( ``eSTYLED_TESSELLATED_ITEM_WITH_COLOURS`` )
    public var COLOUR_VALUES: SDAI.LIST<SDAI.LIST<tUNSIGNED_8_BIT_INTEGER>/*[3:4]*/ >/*[1:nil]*/  {
      get {
        return SDAI.UNWRAP( self.partialEntity._colour_values )
      }
      set(newValue) {
        let partial = self.partialEntity
        partial._colour_values = 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(_styled_tessellated_item_with_colours.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(eSTYLED_ITEM.self) else { return nil }
      self.super_eSTYLED_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"] = _styled_tessellated_item_with_colours.WHERE_wr1(SELF: instance)
      result[prefix2 + " .WHERE_wr2"] = _styled_tessellated_item_with_colours.WHERE_wr2(SELF: instance)
      result[prefix2 + " .WHERE_wr3"] = _styled_tessellated_item_with_colours.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: "STYLED_TESSELLATED_ITEM_WITH_COLOURS", type: self, explicitAttributeCount: 2)

      //MARK: SUPERTYPE REGISTRATIONS
      entityDef.add(supertype: eREPRESENTATION_ITEM.self)
      entityDef.add(supertype: eSTYLED_ITEM.self)
      entityDef.add(supertype: eSTYLED_TESSELLATED_ITEM_WITH_COLOURS.self)

      //MARK: ATTRIBUTE REGISTRATIONS
      entityDef.addAttribute(name: "ITEM", keyPath: \eSTYLED_TESSELLATED_ITEM_WITH_COLOURS.ITEM, 
        kind: .explicitRedeclaring, source: .thisEntity, mayYieldEntityReference: true)
      entityDef.addAttribute(name: "COLOUR_TYPE", keyPath: \eSTYLED_TESSELLATED_ITEM_WITH_COLOURS.COLOUR_TYPE, 
        kind: .explicit, source: .thisEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "COLOURED_COORDINATE_VALUES", keyPath: \eSTYLED_TESSELLATED_ITEM_WITH_COLOURS.COLOURED_COORDINATE_VALUES, 
        kind: .derived, source: .thisEntity, mayYieldEntityReference: true)
      entityDef.addAttribute(name: "STYLES", keyPath: \eSTYLED_TESSELLATED_ITEM_WITH_COLOURS.STYLES, 
        kind: .explicit, source: .superEntity, mayYieldEntityReference: true)
      entityDef.addAttribute(name: "COLOUR_VALUES", keyPath: \eSTYLED_TESSELLATED_ITEM_WITH_COLOURS.COLOUR_VALUES, 
        kind: .explicit, source: .thisEntity, mayYieldEntityReference: false)
      entityDef.addAttribute(name: "NAME", keyPath: \eSTYLED_TESSELLATED_ITEM_WITH_COLOURS.NAME, 
        kind: .explicit, source: .superEntity, mayYieldEntityReference: false)

      return entityDef
    }

  }
}
