package com.gnx.telemedicine.mappers;

import com.gnx.telemedicine.dto.patient_safety.ClinicalAlertRequestDto;
import com.gnx.telemedicine.dto.patient_safety.ClinicalAlertResponseDto;
import com.gnx.telemedicine.model.ClinicalAlert;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface ClinicalAlertMapper {
    
    @Mapping(target = "patient", ignore = true)
    @Mapping(target = "doctor", ignore = true)
    @Mapping(target = "relatedPrescription", ignore = true)
    @Mapping(target = "acknowledgedBy", ignore = true)
    @Mapping(target = "resolvedBy", ignore = true)
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "acknowledgedAt", ignore = true)
    @Mapping(target = "resolvedAt", ignore = true)
    @Mapping(target = "createdAt", ignore = true)
    ClinicalAlert toClinicalAlert(ClinicalAlertRequestDto dto);
    
    @Mapping(target = "patientId", source = "patient.id")
    @Mapping(target = "patientName", expression = "java(alert.getPatient().getUser().getFirstName() + \" \" + alert.getPatient().getUser().getLastName())")
    @Mapping(target = "doctorId", source = "doctor.id")
    @Mapping(target = "doctorName", expression = "java(alert.getDoctor() != null && alert.getDoctor().getUser() != null ? alert.getDoctor().getUser().getFirstName() + \" \" + alert.getDoctor().getUser().getLastName() : null)")
    @Mapping(target = "relatedPrescriptionId", source = "relatedPrescription.id")
    @Mapping(target = "acknowledgedById", source = "acknowledgedBy.id")
    @Mapping(target = "acknowledgedByName", expression = "java(alert.getAcknowledgedBy() != null ? alert.getAcknowledgedBy().getFirstName() + \" \" + alert.getAcknowledgedBy().getLastName() : null)")
    @Mapping(target = "resolvedById", source = "resolvedBy.id")
    @Mapping(target = "resolvedByName", expression = "java(alert.getResolvedBy() != null ? alert.getResolvedBy().getFirstName() + \" \" + alert.getResolvedBy().getLastName() : null)")
    ClinicalAlertResponseDto toClinicalAlertResponseDto(ClinicalAlert alert);
}

