package com.gnx.telemedicine.mappers;

import com.gnx.telemedicine.dto.medical.LabResultRequestDto;
import com.gnx.telemedicine.dto.medical.LabResultResponseDto;
import com.gnx.telemedicine.model.LabResult;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface LabResultMapper {
    
    @Mapping(target = "medicalRecord", ignore = true)
    @Mapping(target = "patient", ignore = true)
    @Mapping(target = "orderedBy", ignore = true)
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "createdAt", ignore = true)
    LabResult toLabResult(LabResultRequestDto dto);
    
    @Mapping(target = "medicalRecordId", source = "medicalRecord.id")
    @Mapping(target = "patientId", source = "patient.id")
    @Mapping(target = "patientName", expression = "java(labResult.getPatient().getUser().getFirstName() + \" \" + labResult.getPatient().getUser().getLastName())")
    @Mapping(target = "orderedById", source = "orderedBy.id")
    @Mapping(target = "orderedByName", expression = "java(labResult.getOrderedBy() != null ? labResult.getOrderedBy().getFirstName() + \" \" + labResult.getOrderedBy().getLastName() : null)")
    LabResultResponseDto toLabResultResponseDto(LabResult labResult);
}

