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

    ### Attribute Readers ###
    # @return [MySchemaKey]
    attr_reader :payload_key

    ### Attribute Accessors ###
    # @return [String]
    attr_accessor :test_id
    # @return [Integer]
    attr_accessor :some_int

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

    # @override
    def initialize(_from_message: false, test_id: nil,
                   some_int: nil,
                   payload_key: nil)
      @_from_message = _from_message
      super
      self.test_id = test_id
      self.some_int = some_int
      self.payload_key = payload_key
    end

    # @override
    def schema
      'MySchema'
    end

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

    def self.tombstone(key)
      record = self.allocate
      record.tombstone_key = MySchemaKey.initialize_from_value(key)
      record.payload_key = key
      record
    end

    # @override
    def as_json(_opts={})
      {
        'test_id' => @test_id,
        'some_int' => @some_int,
        'payload_key' => @payload_key&.as_json
      }
    end
  end
end; end
