package com.hepl.tunefortwo.mapper;

import java.util.List;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import com.hepl.tunefortwo.dto.FormRequestDto;
import com.hepl.tunefortwo.dto.FormRequestDtoCoAdmin;
import com.hepl.tunefortwo.dto.MixtureMaster;
import com.hepl.tunefortwo.entity.Form;

@Mapper(componentModel = "spring")
public interface FormMapper {
@Mapping(target = "createdDate", expression = "java(java.time.LocalDateTime.now())")
@Mapping(source = "masterRequest", target = "mixtureMaster", qualifiedByName = "mapMasterRequestToString")
@Mapping(target = "status", ignore = true)
Form toFormEntity(FormRequestDto formRequestDto);
@Named("mapMasterRequestToString")
default String mapMasterRequestToString(MixtureMaster masterRequest) {
    return masterRequest != null ? masterRequest.toString() : null;
}
@Mapping(source = "orderPosition", target = "orderPosition")
@Mapping(source = "screenshot", target = "screenshot")
@Mapping(source = "status", target = "status")
@Mapping(source = "mixtureMaster" , target = "mixtureMaster")
@Mapping(source = "images", target = "images")
@Mapping(source = "adminClipPath", target = "adminClipPath")
@Mapping(source = "video", target = "videoPath")
@Mapping(source = "orderTotal", target = "orderTotal")
@Mapping(source = "activeStatus", target = "activeStatus")
@Mapping(source = "paymentId", target = "paymentId")
FormRequestDto toDto(Form form);

@Mapping(source = "orderPosition", target = "orderPosition")
//@Mapping(source = "screenshot", target = "screenshot")
@Mapping(source = "status", target = "status")
@Mapping(source = "mixtureMaster" , target = "mixtureMaster")
@Mapping(source = "images", target = "images")
@Mapping(source = "adminClipPath", target = "adminClipPath")
@Mapping(source = "video", target = "videoPath")
FormRequestDtoCoAdmin toDtoCoAdmin(Form form);


//default String getLastOrderPosition(Form form) {
//    List<String> orderPositions = form.getOrderPosition();
//    if (orderPositions != null && !orderPositions.isEmpty()) {
//        return orderPositions.get(orderPositions.size() - 1); 
//    } else {
//        return null; 
//    }
//}

}   
