package com.iqser.red.service.persistence.management.v1.processor.dataexchange.models;

import java.util.LinkedList;
import java.util.List;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DatasetExchangeImportModel {

    private ImportTemplateResult importTemplateResult = ImportTemplateResult.builder().build();
    private List<Dossier> dossiers = new LinkedList<>();

    @Builder
    @Getter
    @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
    public static class Dossier {

        String name;
        @Builder.Default
        List<File> files = new LinkedList<>();

    }

    @Getter
    @AllArgsConstructor
    @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
    public static class File {

        String name;
        byte[] data;

    }


    public DatasetExchangeImportModel.Dossier getOrCreateDossier(String name) {

        for (Dossier dossier : dossiers) {
            if (dossier.getName().equals(name)) {
                return dossier;
            }
        }
        Dossier dossier = Dossier.builder().name(name).build();
        dossiers.add(dossier);
        return dossier;
    }

}
