package com.gnx.telemedicine.mappers;

import com.gnx.telemedicine.dto.medical.MedicalRecordRequestDto;
import com.gnx.telemedicine.dto.medical.MedicalRecordResponseDto;
import com.gnx.telemedicine.model.MedicalRecord;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface MedicalRecordMapper {
    
    @Mapping(target = "patient", ignore = true)
    @Mapping(target = "doctor", ignore = true)
    @Mapping(target = "appointment", ignore = true)
    @Mapping(target = "createdBy", ignore = true)
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "createdAt", ignore = true)
    @Mapping(target = "updatedAt", ignore = true)
    MedicalRecord toMedicalRecord(MedicalRecordRequestDto dto);
    
    @Mapping(target = "patientId", source = "patient.id")
    @Mapping(target = "patientName", expression = "java(medicalRecord.getPatient().getUser().getFirstName() + \" \" + medicalRecord.getPatient().getUser().getLastName())")
    @Mapping(target = "doctorId", source = "doctor.id")
    @Mapping(target = "doctorName", expression = "java(medicalRecord.getDoctor().getUser().getFirstName() + \" \" + medicalRecord.getDoctor().getUser().getLastName())")
    @Mapping(target = "appointmentId", source = "appointment.id")
    @Mapping(target = "createdById", source = "createdBy.id")
    @Mapping(target = "createdByName", expression = "java(medicalRecord.getCreatedBy().getFirstName() + \" \" + medicalRecord.getCreatedBy().getLastName())")
    MedicalRecordResponseDto toMedicalRecordResponseDto(MedicalRecord medicalRecord);
}

