# typed: strict
# frozen_string_literal: true

module RuboCop
  module Cask
    module AST
      # This class wraps the AST method node that represents the cask header. It
      # includes various helper methods to aid cops in their analysis.
      class CaskHeader
        sig { params(method_node: T.all(RuboCop::AST::Node, RuboCop::AST::ParameterizedNode::RestArguments)).void }
        def initialize(method_node)
          @method_node = method_node
        end

        sig { returns(T.all(RuboCop::AST::Node, RuboCop::AST::ParameterizedNode::RestArguments)) }
        attr_reader :method_node

        sig { returns(Parser::Source::Range) }
        def source_range
          @source_range ||= T.let(method_node.loc.expression, T.nilable(Parser::Source::Range))
        end

        sig { returns(String) }
        def cask_token
          @cask_token ||= T.let(method_node.first_argument.str_content, T.nilable(String))
        end

        sig { returns(T.all(RuboCop::AST::Node, RuboCop::AST::ParameterizedNode::RestArguments)) }
        def hash_node
          @hash_node ||= T.let(method_node.each_child_node(:hash).first, T.nilable(RuboCop::AST::Node))
        end
      end
    end
  end
end
