import '../../marianumconnect_query.dart';

/// Submits an absence report (`POST absence`, bearer-auth, `source=mobile`).
/// Empty identity fields are backfilled from LDAP server-side; validation
/// (all fields required, class must exist, no past start date, end >= start)
/// also runs server-side and mirrors the client checks.
class AbsenceSubmit extends MarianumConnectQuery {
  AbsenceSubmit({super.dio});

  Future<void> run({
    required String firstName,
    required String lastName,
    required String className,
    required DateTime absentFrom,
    required DateTime absentUntil,
    required String phone,
    required String note,
  }) => guard(() async {
    await dio.post<void>(
      endpoint('absence'),
      data: {
        'firstName': firstName,
        'lastName': lastName,
        'className': className,
        'absentFrom': isoDate(absentFrom),
        'absentUntil': isoDate(absentUntil),
        'phone': phone,
        'note': note,
      },
    );
  });
}
