package com.gnx.telemedicine.mappers;

import com.gnx.telemedicine.dto.prescription.PrescriptionRequestDto;
import com.gnx.telemedicine.dto.prescription.PrescriptionResponseDto;
import com.gnx.telemedicine.model.Prescription;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface PrescriptionMapper {
    
    @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 = "prescriptionNumber", ignore = true)
    @Mapping(target = "EPrescriptionSent", ignore = true)
    @Mapping(target = "EPrescriptionSentAt", ignore = true)
    @Mapping(target = "createdAt", ignore = true)
    Prescription toPrescription(PrescriptionRequestDto dto);
    
    @Mapping(target = "patientId", source = "patient.id")
    @Mapping(target = "patientName", expression = "java(prescription.getPatient().getUser().getFirstName() + \" \" + prescription.getPatient().getUser().getLastName())")
    @Mapping(target = "doctorId", source = "doctor.id")
    @Mapping(target = "doctorName", expression = "java(prescription.getDoctor().getUser().getFirstName() + \" \" + prescription.getDoctor().getUser().getLastName())")
    @Mapping(target = "appointmentId", source = "appointment.id")
    @Mapping(target = "createdById", source = "createdBy.id")
    @Mapping(target = "createdByName", expression = "java(prescription.getCreatedBy().getFirstName() + \" \" + prescription.getCreatedBy().getLastName())")
    PrescriptionResponseDto toPrescriptionResponseDto(Prescription prescription);
}

