<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
# frozen_string_literal: true

module Bundler
  class Resolver
    class SpecGroup
      attr_reader :specs

      def initialize(specs)
        @specs = specs
      end

      def empty?
        @specs.empty?
      end

      def name
        @name ||= exemplary_spec.name
      end

      def version
        @version ||= exemplary_spec.version
      end

      def source
        @source ||= exemplary_spec.source
      end

      def to_specs(force_ruby_platform, most_specific_locked_platform)
        @specs.map do |s|
          lazy_spec = LazySpecification.from_spec(s)
          lazy_spec.force_ruby_platform = force_ruby_platform
          lazy_spec.most_specific_locked_platform = most_specific_locked_platform
          lazy_spec
        end
      end

      def to_s
        sorted_spec_names.join(", ")
      end

      def dependencies
        @dependencies ||= @specs.flat_map(&:expanded_dependencies).uniq.sort
      end

      def ==(other)
        sorted_spec_names == other.sorted_spec_names
      end

      def merge(other)
        return false unless equivalent?(other)

        @specs |= other.specs

        true
      end

      protected

      def sorted_spec_names
        @specs.map(&:full_name).sort
      end

      private

      def equivalent?(other)
        name == other.name && version == other.version && source == other.source && dependencies == other.dependencies
      end

      def exemplary_spec
        @specs.first
      end
    end
  end
end
