# frozen_string_literal: true

# This file is autogenerated by Deimos, Do NOT modify
module Schemas; module MyNamespace
  ### Primary Schema Class ###
  # Autogenerated Schema for Record at com.my-namespace.MySchemaWithCircularReference
  class MySchemaWithCircularReference < Deimos::SchemaClass::Record

    ### Secondary Schema Classes ###
    # Autogenerated Schema for Record at com.my-namespace.Property
    class Property < Deimos::SchemaClass::Record
  
      ### Attribute Accessors ###
      # @return [Boolean, Integer, Integer, Float, Float, String, Array<Property>, Hash<String, Property>]
      attr_accessor :property
  
      # @override
      def initialize(_from_message: false, property: nil)
        @_from_message = _from_message
        super
        self.property = property
      end
  
      # @override
      def schema
        'Property'
      end
  
      # @override
      def namespace
        'com.my-namespace'
      end
  
      # @override
      def as_json(_opts={})
        {
          'property' => @property
        }
      end
    end


    ### Attribute Readers ###
    # @return [Hash<String, Property>]
    attr_reader :properties

    ### Attribute Writers ###
    # @return [Hash<String, Property>]
    def properties=(values)
      @properties = values&.transform_values do |value|
        Property.initialize_from_value(value, from_message: self._from_message)
      end
    end

    # @override
    def initialize(_from_message: false, properties: {})
      @_from_message = _from_message
      super
      self.properties = properties
    end

    # @override
    def schema
      'MySchemaWithCircularReference'
    end

    # @override
    def namespace
      'com.my-namespace'
    end

    def self.tombstone(key)
      record = self.allocate
      record
    end

    # @override
    def as_json(_opts={})
      {
        'properties' => @properties.transform_values { |v| v&.as_json }
      }
    end
  end
end; end
