import 'package:flutter_test/flutter_test.dart';
import 'package:health_app/pages/care_plan_ui_logic.dart';

void main() {
  group('care plan lifecycle', () {
    final today = DateTime(2026, 7, 13);

    test('separates active, upcoming, and ended records', () {
      expect(
        resolveCarePlanPhase(
          startDate: '2026-07-01',
          endDate: '2026-07-20',
          today: today,
        ),
        CarePlanPhase.active,
      );
      expect(
        resolveCarePlanPhase(
          startDate: '2026-07-14',
          endDate: '2026-07-20',
          today: today,
        ),
        CarePlanPhase.upcoming,
      );
      expect(
        resolveCarePlanPhase(
          startDate: '2026-06-01',
          endDate: '2026-07-12',
          today: today,
        ),
        CarePlanPhase.ended,
      );
    });

    test('disabled medication is treated as ended', () {
      expect(
        resolveCarePlanPhase(
          enabled: false,
          startDate: '2026-07-01',
          endDate: '2026-07-20',
          today: today,
        ),
        CarePlanPhase.ended,
      );
    });
  });

  group('medication form validation', () {
    test('requires dosage', () {
      expect(
        validateMedicationForm(
          name: '阿司匹林',
          dosage: '',
          times: const ['08:00'],
          startDate: DateTime(2026, 7, 13),
        ),
        '请输入服药剂量',
      );
    });

    test('rejects duplicate dose times', () {
      expect(
        validateMedicationForm(
          name: '阿司匹林',
          dosage: '100mg',
          times: const ['08:00', '08:00'],
          startDate: DateTime(2026, 7, 13),
        ),
        '服药时间不能重复',
      );
    });

    test('rejects an end date before the start date', () {
      expect(
        validateMedicationForm(
          name: '阿司匹林',
          dosage: '100mg',
          times: const ['08:00'],
          startDate: DateTime(2026, 7, 13),
          endDate: DateTime(2026, 7, 12),
        ),
        '结束日期不能早于开始日期',
      );
    });
  });
}
