package com.gnx.telemedicine.mappers;

import com.gnx.telemedicine.dto.patient_safety.SentinelEventRequestDto;
import com.gnx.telemedicine.dto.patient_safety.SentinelEventResponseDto;
import com.gnx.telemedicine.model.SentinelEvent;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface SentinelEventMapper {
    
    @Mapping(target = "patient", ignore = true)
    @Mapping(target = "doctor", ignore = true)
    @Mapping(target = "appointment", ignore = true)
    @Mapping(target = "reportedBy", ignore = true)
    @Mapping(target = "resolvedBy", ignore = true)
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "reportedAt", ignore = true)
    @Mapping(target = "createdAt", ignore = true)
    @Mapping(target = "status", ignore = true)
    SentinelEvent toSentinelEvent(SentinelEventRequestDto dto);
    
    @Mapping(target = "patientId", source = "patient.id")
    @Mapping(target = "patientName", expression = "java(event.getPatient() != null ? event.getPatient().getUser().getFirstName() + \" \" + event.getPatient().getUser().getLastName() : null)")
    @Mapping(target = "doctorId", source = "doctor.id")
    @Mapping(target = "doctorName", expression = "java(event.getDoctor() != null ? event.getDoctor().getUser().getFirstName() + \" \" + event.getDoctor().getUser().getLastName() : null)")
    @Mapping(target = "appointmentId", source = "appointment.id")
    @Mapping(target = "reportedById", source = "reportedBy.id")
    @Mapping(target = "reportedByName", expression = "java(event.getReportedBy() != null ? event.getReportedBy().getFirstName() + \" \" + event.getReportedBy().getLastName() : null)")
    @Mapping(target = "resolvedById", source = "resolvedBy.id")
    @Mapping(target = "resolvedByName", expression = "java(event.getResolvedBy() != null ? event.getResolvedBy().getFirstName() + \" \" + event.getResolvedBy().getLastName() : null)")
    SentinelEventResponseDto toSentinelEventResponseDto(SentinelEvent event);
}

