# frozen_string_literal: true

module Decidim
  module Attributes
    autoload :TimeWithZone, "decidim/attributes/time_with_zone"
    autoload :LocalizedDate, "decidim/attributes/localized_date"
    autoload :CleanString, "decidim/attributes/clean_string"
    autoload :RichText, "decidim/attributes/rich_text"
    autoload :Blob, "decidim/attributes/blob"
    autoload :Array, "decidim/attributes/array"
    autoload :Hash, "decidim/attributes/hash"
    autoload :Object, "decidim/attributes/object"
    autoload :Model, "decidim/attributes/model"
    autoload :Symbol, "decidim/attributes/symbol"
    autoload :Integer, "decidim/attributes/integer"
    autoload :IntegerWithUnits, "decidim/attributes/integer_with_units"

    # Base types
    ActiveModel::Type.register(:array, Decidim::Attributes::Array)
    ActiveModel::Type.register(:hash, Decidim::Attributes::Hash)
    ActiveModel::Type.register(:object, Decidim::Attributes::Object)
    ActiveModel::Type.register(:model, Decidim::Attributes::Model)
    ActiveModel::Type.register(:symbol, Decidim::Attributes::Symbol)

    # Synonyms
    ActiveModel::Type.register(:date_time, ActiveModel::Type::DateTime) # Synonym for :datetime

    # Extra types
    ActiveModel::Type.register(:"decidim/attributes/time_with_zone", Decidim::Attributes::TimeWithZone)
    ActiveModel::Type.register(:"decidim/attributes/localized_date", Decidim::Attributes::LocalizedDate)
    ActiveModel::Type.register(:"decidim/attributes/clean_string", Decidim::Attributes::CleanString)
    ActiveModel::Type.register(:"decidim/attributes/rich_text", Decidim::Attributes::RichText)
    ActiveModel::Type.register(:"decidim/attributes/blob", Decidim::Attributes::Blob)
    ActiveModel::Type.register(:"decidim/attributes/integer_with_units", Decidim::Attributes::IntegerWithUnits)

    ActiveModel::Type.register(:integer, Decidim::Attributes::Integer)
  end
end
