# frozen_string_literal: true

# noinspection RubyConstantNamingConvention

require 'dry-auto_inject'
require 'dry-container'
require 'dry-configurable'

# rubocop:disable Style/Documentation

module Dry
  module Plugins
    extend Dry::Container::Mixin

    Import = Dry.AutoInject(self)

    # @!parse
    #   # Global configuration of {Dry::Plugins}
    #   #
    #   # @!group Method names
    #   #
    #   # @!attribute [rw] configure_method
    #   #   Name of the method that will be used for configuration when
    #   #   {Dry::Plugins::Host::DSL#use} called with block
    #   #   @return [Symbol]
    #   #   @default `:configure`
    #   #
    #   # @!attribute [rw] load_dependencies_method
    #   #   Name of the method that will be used for loading dependencies when
    #   #   {Dry::Plugins::Host::DSL#use} called
    #   #   @return [Symbol]
    #   #   @default `:load_dependencies`
    #   #
    #   # @!attribute [rw] registry_method
    #   #   @return [Symbol]
    #   #   @default `:plugins_registry`
    #   #
    #   # @!group Constant names
    #   #
    #   # @!attribute [rw] class_interface_name
    #   #   Name of the module that will be used as a class extension
    #   #   when plug-in is included
    #   #   @return [Symbol]
    #   #   @default `:ClassInterface`
    #   #
    #   # @!attribute [rw] plugins_module_name
    #   #   Name of the module that will be used for plug-ins
    #   #   @return [Symbol]
    #   #   @default `:Plugins`
    #   #
    #   # @!attribute [rw] registry_class_name
    #   #   Name of the class that will be used for plug-ins registry
    #   #   @return [Symbol]
    #   #   @default `:Registry`
    #   #
    #   class Config < Dry::Configurable::Config
    #   end
    #
    # @!method self.config
    #   @return [Config]
    #
    # @!method self.configure
    #   @yieldparam config [Config]
    #
    #   @return [Config]
    #
    #   @see Config#configure_method config.configure_method
    #   @see Config#load_dependencies_method config.load_dependencies_method
    #   @see Config#registry_method config.registry_method
    #   @see Config#class_interface_name config.class_interface_name
    #   @see Config#plugins_module_name config.plugins_module_name
    #   @see Config#registry_class_name config.registry_class_name
    #
    #   @example dry-plugins default configuration
    #     Dry::Plugins.configure do |config|
    #       config.configure_method = :configure
    #       config.load_dependencies_method = :load_dependencies
    #       config.class_interface_name = :ClassInterface
    #       config.plugins_module_name = :Plugins
    #       config.registry_class_name = :Registry
    #     end
    setting :container, Dry::Plugins
    setting :configure_method, :configure
    setting :load_dependencies_method, :load_dependencies
    setting :registry_method, :plugins_registry
    setting :class_interface_name, :ClassInterface
    setting :plugins_module_name, :Plugins
    setting :registry_class_name, :Registry

    register :host_builder do
      require 'dry/plugins/host/builder'
      Host::Builder.new
    end

    register :module_builder do
      require 'dry/plugins/module_builder'
      ModuleBuilder.new
    end

    register :builder do
      require 'dry/plugins/builder'
      Builder.new
    end

    register :registry_builder do
      require 'dry/plugins/registry/builder'
      Registry::Builder.new
    end

    register :registry_class_builder do
      require 'dry/plugins/registry/class_builder'
      Registry::ClassBuilder.new
    end
  end
end