import 'package:flutter_test/flutter_test.dart';
import 'package:marianum_mobile/view/pages/timetable/data/subject_color_palette.dart';

void main() {
  group('SubjectColorPalette.colorFromName', () {
    test('resolves every palette name to a concrete colour', () {
      for (final option in SubjectColor.values) {
        expect(
          SubjectColorPalette.colorFromName(option.name),
          SubjectColorPalette.displayOf(option).color,
          reason: '${option.name} should round-trip to its display colour',
        );
      }
    });

    test('returns null for null, empty or unknown names', () {
      expect(SubjectColorPalette.colorFromName(null), isNull);
      expect(SubjectColorPalette.colorFromName(''), isNull);
      expect(SubjectColorPalette.colorFromName('not-a-colour'), isNull);
    });
  });

  group('SubjectColorPalette.fromName legacy aliases', () {
    test('maps the old 4-colour custom-event names to palette colours', () {
      // Bestehende eigene Termine wurden mit diesen Namen gespeichert und
      // dürfen nicht ihre Farbe verlieren.
      expect(SubjectColorPalette.fromName('orange'), SubjectColor.amber);
      expect(SubjectColorPalette.fromName('red'), SubjectColor.deepOrange);
      expect(SubjectColorPalette.fromName('green'), SubjectColor.teal);
      expect(SubjectColorPalette.fromName('blue'), SubjectColor.indigo);
    });

    test('new palette names take precedence and resolve directly', () {
      expect(SubjectColorPalette.fromName('teal'), SubjectColor.teal);
      expect(SubjectColorPalette.fromName('amber'), SubjectColor.amber);
    });
  });
}
