import 'package:intl/intl.dart';
import 'package:school_management_system/api/student_requests.dart';

late DateTime dateOfBirth;

Map<String, dynamic> getPersonalDetails(Student studentDetail) {
  Map<String, dynamic> personalDetails = {};

  if (studentDetail.dateofbirth != null) {
    dateOfBirth = studentDetail.dateofbirth!;
  } else {
    dateOfBirth = DateTime.now();
  }

  personalDetails.addEntries({'Title': studentDetail.title}.entries);
  personalDetails.addEntries({
    'Full Name': "${studentDetail.firstname}  ${studentDetail.lastname}"
  }.entries);
  personalDetails.addEntries({'Gender': studentDetail.gender}.entries);
  personalDetails.addEntries({
    'Date of Birth': DateFormat('MMMM, dd yyyy').format(dateOfBirth)
  }.entries);
  personalDetails
      .addEntries({'Current Year': studentDetail.currentyear}.entries);
  personalDetails
      .addEntries({'Current Session': studentDetail.currentsession}.entries);
  personalDetails.addEntries({
    'Course of Study': studentDetail.coursedetails![0].courseofstudy
  }.entries);
  personalDetails.addEntries(
      {'Course Type': studentDetail.coursedetails![0].coursetype}.entries);
  personalDetails.addEntries({
    'Course Qualification': studentDetail.coursedetails![0].coursequalification
  }.entries);
  personalDetails.addEntries(
      {'Course Mode': studentDetail.coursedetails![0].coursemode}.entries);

  return personalDetails;
}

Map<String, dynamic> getContactDetails(Student studentDetail) {
  Map<String, dynamic> contactDetails = {};

  contactDetails
      .addEntries({'Home Address': studentDetail.homeaddress}.entries);
  contactDetails
      .addEntries({'Mobile Number': studentDetail.mobilenumber}.entries);
  contactDetails
      .addEntries({'E-Mail Address': studentDetail.emailaddress}.entries);
  contactDetails
      .addEntries({'School Email': studentDetail.schoolemail}.entries);
  contactDetails.addEntries({
    'Next of Kin Name ': studentDetail.nextofkindetails![0].nextofkinname
  }.entries);
  contactDetails.addEntries({
    'Next of Kin Contact ': studentDetail.nextofkindetails![0].nextofkincontact
  }.entries);
  contactDetails.addEntries({
    'Next of Kin Address ': studentDetail.nextofkindetails![0].nextofkinaddress
  }.entries);
  contactDetails.addEntries({
    'Next of Kin Relationship ': studentDetail.nextofkindetails![0].nextofkinrelationship
  }.entries);
  contactDetails.addEntries({
    'Guardian Name ': studentDetail.guardiandetails![0].guardianname
  }.entries);
  contactDetails.addEntries({
    'Guardian Contact ': studentDetail.guardiandetails![0].guardiancontact
  }.entries);
  contactDetails.addEntries({
    'Guardian Address ': studentDetail.guardiandetails![0].guardianaddress
  }.entries);
  contactDetails.addEntries({
    'Guardian Relationship ': studentDetail.guardiandetails![0].guardianrelationship
  }.entries);

  return contactDetails;
}

Map<String, dynamic> getMedicalDetails(Student studentDetail) {
  Map<String, dynamic> medicalDetails = {};

  medicalDetails
      .addEntries({'Weight': studentDetail.medicaldetails![0].weight}.entries);
  medicalDetails
      .addEntries({'Height': studentDetail.medicaldetails![0].height}.entries);
  medicalDetails.addEntries(
      {'Genotype': studentDetail.medicaldetails![0].genotype}.entries);
  medicalDetails.addEntries(
      {'Blood Group': studentDetail.medicaldetails![0].bloodgroup}.entries);
  medicalDetails.addEntries(
      {'DNR': studentDetail.medicaldetails![0].dnr.toString()}.entries);
  medicalDetails.addEntries(
      {'Allergies': studentDetail.medicaldetails![0].allergies}.entries);
  medicalDetails.addEntries({
    'Medical Condition': studentDetail.medicaldetails![0].medicalcondition
  }.entries);
    medicalDetails.addEntries({
    'Emergency Contact': studentDetail.medicaldetails![0].emergencycontactname
  }.entries);
  medicalDetails.addEntries({
    'Emergency Number': studentDetail.medicaldetails![0].emergencycontactnumber
  }.entries);
    medicalDetails.addEntries({
    'Emergency Relationship': studentDetail.medicaldetails![0].emergencycontractrelationship
  }.entries);

  return medicalDetails;
}
