package com.eactive.testmaster.client.mapper;

import com.eactive.testmaster.client.dto.ApiLayoutItemDTO;
import com.eactive.testmaster.client.entity.ApiLayoutItem;
import com.eactive.testmaster.client.repository.ApiLayoutItemRepository;
import com.eactive.testmaster.common.mapper.CommonMapper;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Mapper(componentModel = "spring",
    uses = {CommonMapper.class},
    unmappedTargetPolicy = ReportingPolicy.IGNORE)
@Component
public abstract class ApiLayoutItemMapper {

    @Autowired
    private ApiLayoutItemRepository apiLayoutItemRepository;

    public abstract ApiLayoutItem map(ApiLayoutItemDTO dto);

    public abstract ApiLayoutItemDTO map(ApiLayoutItem entity);

    public ApiLayoutItem map(Long id) {
        if (id == null) {
            return null;
        }
        return apiLayoutItemRepository.findById(id)
            .orElseThrow(() -> new IllegalArgumentException("No ApiLayoutItem found for ID: " + id));
    }

    // Method to map lists of ApiLayoutItemDTOs to lists of ApiLayoutItem entities
    public abstract List<ApiLayoutItem> mapItems(List<ApiLayoutItemDTO> dtos);

    // Method to map lists of ApiLayoutItem entities to lists of ApiLayoutItemDTOs
    public abstract List<ApiLayoutItemDTO> mapItemDTOs(List<ApiLayoutItem> entities);

}
