# 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.MySchemaWithComplexTypes
  class MySchemaWithComplexType < Deimos::SchemaClass::Record

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

    # Autogenerated Schema for Enum at com.my-namespace.AnEnum
    class AnEnum < Deimos::SchemaClass::Enum
      # @override
      def symbols
        %w(sym1 sym2)
      end
  
      
      def sym1?
        @value == 'sym1'
      end
      
      def sym2?
        @value == 'sym2'
      end
      
    end

    # Autogenerated Schema for Enum at com.my-namespace.AnotherEnum
    class AnotherEnum < Deimos::SchemaClass::Enum
      # @override
      def symbols
        %w(sym3 sym4)
      end
  
      
      def sym3?
        @value == 'sym3'
      end
      
      def sym4?
        @value == 'sym4'
      end
      
    end

    # Autogenerated Schema for Enum at com.my-namespace.YetAnotherEnum
    class YetAnotherEnum < Deimos::SchemaClass::Enum
      # @override
      def symbols
        %w(sym5 sym6)
      end
  
      
      def sym5?
        @value == 'sym5'
      end
      
      def sym6?
        @value == 'sym6'
      end
      
    end


    ### Attribute Readers ###
    # @return [ARecord]
    attr_reader :some_record
    # @return [nil, ARecord]
    attr_reader :some_optional_record
    # @return [Array<ARecord>]
    attr_reader :some_record_array
    # @return [Hash<String, ARecord>]
    attr_reader :some_record_map
    # @return [Array<AnEnum>]
    attr_reader :some_enum_array
    # @return [nil, AnotherEnum]
    attr_reader :some_optional_enum
    # @return [YetAnotherEnum]
    attr_reader :some_enum_with_default

    ### Attribute Accessors ###
    # @return [String]
    attr_accessor :test_id
    # @return [String, nil]
    attr_accessor :union_string
    # @return [Float]
    attr_accessor :test_float
    # @return [Array<String>]
    attr_accessor :test_string_array
    # @return [Array<Integer>]
    attr_accessor :test_int_array
    # @return [Integer, nil]
    attr_accessor :test_optional_int
    # @return [Hash<String, Integer>]
    attr_accessor :some_integer_map

    ### Attribute Writers ###
    # @return [ARecord]
    def some_record=(value)
      @some_record = ARecord.initialize_from_value(value, from_message: self._from_message)
    end

    # @return [nil, ARecord]
    def some_optional_record=(value)
      @some_optional_record = ARecord.initialize_from_value(value, from_message: self._from_message)
    end

    # @return [Array<ARecord>]
    def some_record_array=(values)
      @some_record_array = values&.map do |value|
        ARecord.initialize_from_value(value, from_message: self._from_message)
      end
    end

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

    # @return [Array<AnEnum>]
    def some_enum_array=(values)
      @some_enum_array = values&.map do |value|
        AnEnum.initialize_from_value(value, from_message: self._from_message)
      end
    end

    # @return [nil, AnotherEnum]
    def some_optional_enum=(value)
      @some_optional_enum = AnotherEnum.initialize_from_value(value, from_message: self._from_message)
    end

    # @return [YetAnotherEnum]
    def some_enum_with_default=(value)
      @some_enum_with_default = YetAnotherEnum.initialize_from_value(value, from_message: self._from_message)
    end

    # @override
    def initialize(_from_message: false, test_id: nil,
                   union_string: "",
                   test_float: nil,
                   test_string_array: ["test"],
                   test_int_array: [123],
                   test_optional_int: 123,
                   some_integer_map: {"abc"=>123},
                   some_record: {"a_record_field"=>"Test String"},
                   some_optional_record: nil,
                   some_record_array: nil,
                   some_record_map: nil,
                   some_enum_array: nil,
                   some_optional_enum: nil,
                   some_enum_with_default: "sym6")
      @_from_message = _from_message
      super
      self.test_id = test_id
      self.union_string = union_string
      self.test_float = test_float
      self.test_string_array = test_string_array
      self.test_int_array = test_int_array
      self.test_optional_int = test_optional_int
      self.some_integer_map = some_integer_map
      self.some_record = some_record
      self.some_optional_record = some_optional_record
      self.some_record_array = some_record_array
      self.some_record_map = some_record_map
      self.some_enum_array = some_enum_array
      self.some_optional_enum = some_optional_enum
      self.some_enum_with_default = some_enum_with_default
    end

    # @override
    def schema
      'MySchemaWithComplexTypes'
    end

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

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

    # @override
    def as_json(_opts={})
      {
        'test_id' => @test_id,
        'union_string' => @union_string,
        'test_float' => @test_float,
        'test_string_array' => @test_string_array,
        'test_int_array' => @test_int_array,
        'test_optional_int' => @test_optional_int,
        'some_integer_map' => @some_integer_map,
        'some_record' => @some_record&.as_json,
        'some_optional_record' => @some_optional_record&.as_json,
        'some_record_array' => @some_record_array.map { |v| v&.as_json },
        'some_record_map' => @some_record_map.transform_values { |v| v&.as_json },
        'some_enum_array' => @some_enum_array.map { |v| v&.as_json },
        'some_optional_enum' => @some_optional_enum&.as_json,
        'some_enum_with_default' => @some_enum_with_default&.as_json
      }
    end
  end
end; end
