package eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel;


import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.LinkedList;
import java.util.List;

@XmlRootElement(name = "pages")
public class DatasetProfile {

    private List<Page> page;

    @XmlElement(name = "page")
    public List<Page> getPage() {
        return page;
    }

    public void setPage(List<Page> page) {
        this.page = page;
    }

    public eu.eudat.models.data.admin.composite.DatasetProfile toAdminCompositeModel(String label){
        eu.eudat.models.data.admin.composite.DatasetProfile newDatasetEntityProfile = new eu.eudat.models.data.admin.composite.DatasetProfile();
        newDatasetEntityProfile.setLabel(label);
        newDatasetEntityProfile.setStatus(eu.eudat.data.entities.DatasetProfile.Status.SAVED.getValue());

        List<eu.eudat.models.data.admin.components.datasetprofile.Page> pagesDatasetEntity = new LinkedList<>();
        List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionDatasetEntity = new LinkedList<>();
        for (Page xmlPage: page) {
            pagesDatasetEntity.add(xmlPage.toAdminCompositeModelPage());
            sectionDatasetEntity.add(xmlPage.toAdminCompositeModelSection());
        }
        newDatasetEntityProfile.setPages(pagesDatasetEntity);
        newDatasetEntityProfile.setSections(sectionDatasetEntity);

        return newDatasetEntityProfile;
    }
}
