// models.dart — Core data models for the generator

/// Full parsed project brief
class ProjectBrief {
  final String projectName;
  final String packageId;
  final String description;
  final String scale; // small | medium | large

  // Stack
  final String stateManagement; // bloc | riverpod | getx | hooks_riverpod
  final String routing;         // gorouter | getx_nav | auto_route
  final String architecture;    // clean | feature_first | mvvm | mvc | layered
  final List<String> backends;  // firebase | supabase | rest
  final String auth;            // firebase_auth | supabase_auth | jwt_rest | oauth2 | none

  // NEW — Pillar 4: platform targets
  final List<String> platforms;     // ios | android | web | desktop
  final List<String> codegenTools;  // freezed | json_serializable | injectable | retrofit

  // Environments
  final List<String> flavors;
  final String cicd; // codemagic | github_actions | fastlane

  // Testing
  final String testingDepth; // unit_widget | integration | e2e | full
  final String e2eTool;      // patrol | maestro

  // Design
  final String designSource;
  final String figmaUrl;

  // API docs
  final String apiDocsFormat; // openapi | postman | markdown | none
  final String apiDocsPath;

  // References
  final List<String> referenceRepos;
  final List<String> localPaths;

  // Features
  final List<String> featureModules;
  final List<String> specialFeatures; // realtime | push_notifications | deep_linking | offline_first

  // Localization
  final bool i18nEnabled;
  final List<String> locales;

  // Template version lock (Pillar 1)
  final String? cursorTemplatesVersion;

  // Telemetry opt-in (Pillar 6)
  final bool telemetryOptIn;

  /// Theme variants to support (subset of light, dark, high_contrast).
  final List<String> themeVariants;

  /// App-level RBAC: when true, [roleNames] should list concrete roles.
  final bool rolesEnabled;
  final List<String> roleNames;

  const ProjectBrief({
    required this.projectName,
    required this.packageId,
    required this.description,
    required this.scale,
    required this.stateManagement,
    required this.routing,
    required this.architecture,
    required this.backends,
    required this.auth,
    required this.platforms,
    required this.codegenTools,
    required this.flavors,
    required this.cicd,
    required this.testingDepth,
    required this.e2eTool,
    required this.designSource,
    required this.figmaUrl,
    required this.apiDocsFormat,
    required this.apiDocsPath,
    required this.referenceRepos,
    required this.localPaths,
    required this.featureModules,
    required this.specialFeatures,
    required this.i18nEnabled,
    required this.locales,
    this.cursorTemplatesVersion,
    this.telemetryOptIn = false,
    this.themeVariants = const ['light', 'dark'],
    this.rolesEnabled = false,
    this.roleNames = const [],
  });

  /// Local snapshot for tooling (written as `cursor-gen-metadata.json` under the output dir).
  Map<String, dynamic> toMetadataMap({DateTime? generatedAt}) {
    final at = (generatedAt ?? DateTime.now()).toUtc();
    return {
      'schema_version': 1,
      'generated_at': at.toIso8601String(),
      'project': {
        'name': projectName,
        'package': packageId,
        'description': description,
        'scale': scale,
      },
      'references': {
        'repos': List<String>.from(referenceRepos),
        'local_paths': List<String>.from(localPaths),
      },
      'app_context': {
        'theme_variants': List<String>.from(themeVariants),
        'roles_enabled': rolesEnabled,
        'role_names': List<String>.from(roleNames),
      },
    };
  }
}

class ValidationResult {
  final bool isValid;
  final List<String> errors;
  final List<String> warnings;
  const ValidationResult({required this.isValid, this.errors = const [], this.warnings = const []});
}

class VersionStatus {
  final bool hasUpdate;
  final String currentVersion;
  final String latestVersion;
  final List<String> changelog;
  const VersionStatus({
    required this.hasUpdate,
    required this.currentVersion,
    required this.latestVersion,
    this.changelog = const [],
  });
}

class OverrideSnapshot {
  final List<String> customFiles;        // files in custom/
  final Map<String, String> customSections; // CURSOR:CUSTOM blocks per file
  const OverrideSnapshot({required this.customFiles, required this.customSections});
}
