import 'dart:convert';
import 'dart:io';

import 'package:analyzer/dart/element/element.dart';
import 'package:build/build.dart';
import 'package:code_builder/code_builder.dart';
import 'package:dart_style/dart_style.dart';
import 'package:glob/glob.dart';
import 'package:guru_spec/guru_spec.dart';
import 'package:guru_spec/src/tuple.dart';
import 'package:source_gen/source_gen.dart';
import 'package:yaml/yaml.dart';
import 'package:glob/list_local_fs.dart';

/// Created by Haoyi on 2023/3/1

Builder intelligentKeysGeneratorFactoryBuilder(BuilderOptions options) =>
    SharedPartBuilder([IntelligentKeysGenerator()], "intelligent_keys");

class IntelligentKeysGenerator extends GeneratorForAnnotation<GuruSpecCreator> {
  @override
  generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) {
    if (element is! ClassElement) {
      final name = element.displayName;
      final todo = 'Remove the [GuruSpecCreator] annotation from `$name`.';
      throw InvalidGenerationSourceError(
        'Generator cannot target `$name`.\n[TODO] $todo',
        todo: 'Remove the [GuruSpecCreator] annotation from `$name`.',
      );
    }
    log.info("IntelligentKeysGenerator fields:${element.fields.map((e) => e.name)}");
    log.info("doc:${element.displayName} ");

  }
}
