
using Godot;

using Rokojori;
using System.Collections.Generic;
using System;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Linq;

namespace Rokojori.DocGenerator
{
  public class ClassDocMember
  {   
    public int start;
    public RangeI attributes;
    public RangeI modifiers;
    public RangeI type;
    public int name;
    public int end;  
    public int comment;

    public bool IsMethod( LexerList lexerList )
    {
      var next = lexerList.Get( name + 1, LexerMatcherLibrary.Ignore );

      // RJLog.Log( lexerList[ name ].match, ">>", next.match );
      return lexerList.MatchIs( name + 1, "(", LexerMatcherLibrary.Ignore );
    }

    public List<string> GetMethodParameterTypes( LexerList lexerList )
    {
      var parameters = lexerList.GetParameters( name );

      if ( parameters == null || parameters.Count ==  0 )
      {
        return [];
      }
      
      var list = parameters.Map(
        ( r )=>
        {
          var tokens = lexerList.Range( r );
          tokens = tokens.Filter( t => ! t.IsAnyOf( LexerMatcherLibrary.Ignore ) );

          var assignmentIndex = tokens.FindIndexOfMatch( 0, "=" );

          if ( assignmentIndex != -1 )
          {
            tokens.events.RemoveRange( assignmentIndex, tokens.events.Count - assignmentIndex ); 
          }

          tokens.events.RemoveAt( tokens.events.Count - 1 );

          return tokens.match;
        }
      );

      return list;
    }
  }
}