package com.pack.modeler.assembler;

import com.pack.modeler.structures.UserError;
import com.pack.modeler.dto.ErrorDTO;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ErrorAssembler {
    public Resource<ErrorDTO> toResource(UserError err) {
        ErrorDTO dto = new ErrorDTO();

        dto.setCode(err.getCode());
        dto.setMsg(err.getMsg());

        return new Resource<>(dto);
    }

    public Resources<Resource<ErrorDTO>> toResources(List<UserError> rows){
        return new Resources(
                rows.stream().map(this::toResource).collect(Collectors.toList())
        );
    }
}
