# typed: strict

module Tapioca::Compilers
  class HasColorLoggerDsl < Tapioca::Dsl::Compiler
    extend T::Sig

    ConstantType = type_member { { fixed: T.class_of(::HasColorLogger) } }

    sig { override.returns(T::Enumerable[Module]) }
    def self.gather_constants
      # Collect all the classes that include HasColorLogger
      all_classes.select { |c| c < ::HasColorLogger }
    end

    sig { override.void }
    def decorate
      # Create a RBI definition for each class that includes HasColorLogger
      root.create_path(constant) do |klass|
        klass.create_method("logger", return_type: ColorLogger.name)
        klass.create_method(
          "logger",
          return_type: ColorLogger.name,
          class_method: true,
        )
      end
    end
  end
end
