import 'package:flutter_test/flutter_test.dart';
import 'package:p_tits_pas/models/am_registration_data.dart';
import 'package:p_tits_pas/models/reprise_dossier.dart';
import 'package:p_tits_pas/utils/reprise_mapper.dart';

void main() {
  test('RepriseDossier parse champs AM plats', () {
    final d = RepriseDossier.fromJson({
      'id': 'am1',
      'email': 'marie@test.fr',
      'role': 'assistante_maternelle',
      'date_naissance': '1980-06-08',
      'date_agrement': '2019-09-01',
      'place_disponible': 2,
      'nb_max_enfants': 4,
      'lieu_naissance_ville': 'Ajaccio',
      'nir': '280062A00100191',
      'numero_agrement': 'AGR-2019-095001',
    });

    expect(d.dateNaissance, '1980-06-08');
    expect(d.dateAgrement, '2019-09-01');
    expect(d.placeDisponible, 2);

    final data = AmRegistrationData();
    RepriseMapper.applyAmDossier(data, d);
    expect(data.dateOfBirth, DateTime(1980, 6, 8));
    expect(data.agreementDate, DateTime(2019, 9, 1));
    expect(data.placesAvailable, 2);
  });

  test('RepriseDossier parse champs AM imbriqués + wrapper data', () {
    final d = RepriseDossier.fromJson({
      'id': 'am1',
      'email': 'marie@test.fr',
      'role': 'assistante_maternelle',
      'nir': '280062A00100191',
      'numero_agrement': 'AGR-2019-095001',
      'nb_max_enfants': 4,
      'lieu_naissance_ville': 'Ajaccio',
      'user': {'date_naissance': '1980-06-08T00:00:00.000Z'},
      'dossier': {
        'date_agrement': '2019-09-01',
        'places_disponibles': 2,
      },
    });

    expect(d.dateNaissance, isNotNull);
    expect(d.dateAgrement, '2019-09-01');
    expect(d.placeDisponible, 2);
  });
}
