import 'package:flutter_test/flutter_test.dart';
import 'package:household_keeper/features/tasks/domain/effort_level.dart';
import 'package:household_keeper/features/tasks/domain/frequency.dart';
import 'package:household_keeper/features/templates/data/task_templates.dart';

void main() {
  group('roomTemplates', () {
    test('contains exactly 14 room type keys', () {
      expect(roomTemplates.length, 14);
    });

    test('all 14 room types from TMPL-02 are present', () {
      const expectedTypes = [
        'kueche',
        'badezimmer',
        'schlafzimmer',
        'wohnzimmer',
        'flur',
        'buero',
        'garage',
        'balkon',
        'waschkueche',
        'keller',
        'kinderzimmer',
        'gaestezimmer',
        'esszimmer',
        'garten',
      ];
      for (final type in expectedTypes) {
        expect(
          roomTemplates.containsKey(type),
          isTrue,
          reason: 'Missing room type: $type',
        );
      }
    });

    test('each room type maps to a non-empty list of TaskTemplate objects', () {
      for (final entry in roomTemplates.entries) {
        expect(
          entry.value,
          isNotEmpty,
          reason: 'Room type ${entry.key} has no templates',
        );
      }
    });

    test('every TaskTemplate has a non-empty German name', () {
      for (final entry in roomTemplates.entries) {
        for (final template in entry.value) {
          expect(
            template.name.isNotEmpty,
            isTrue,
            reason:
                'Template in ${entry.key} has empty name',
          );
        }
      }
    });

    test('every TaskTemplate has a valid IntervalType', () {
      for (final entry in roomTemplates.entries) {
        for (final template in entry.value) {
          expect(
            IntervalType.values.contains(template.intervalType),
            isTrue,
            reason:
                'Template "${template.name}" in ${entry.key} has invalid intervalType',
          );
        }
      }
    });

    test('every TaskTemplate has a valid EffortLevel', () {
      for (final entry in roomTemplates.entries) {
        for (final template in entry.value) {
          expect(
            EffortLevel.values.contains(template.effortLevel),
            isTrue,
            reason:
                'Template "${template.name}" in ${entry.key} has invalid effortLevel',
          );
        }
      }
    });
  });

  group('detectRoomType', () {
    test('"Kueche" returns "kueche"', () {
      expect(detectRoomType('Kueche'), 'kueche');
    });

    test('"Mein Badezimmer" returns "badezimmer"', () {
      expect(detectRoomType('Mein Badezimmer'), 'badezimmer');
    });

    test('"Bad" returns "badezimmer" (alias)', () {
      expect(detectRoomType('Bad'), 'badezimmer');
    });

    test('"Random Name" returns null', () {
      expect(detectRoomType('Random Name'), isNull);
    });

    test('is case-insensitive', () {
      expect(detectRoomType('KUECHE'), 'kueche');
      expect(detectRoomType('kueche'), 'kueche');
      expect(detectRoomType('Kueche'), 'kueche');
    });
  });
}
