import http from '../http';
import url from '../url'

export default class datasets {

    static get(datasetID) {

        return http.get(`/dataset/datasets/${datasetID}`)
            .then(response => {
                return response;
            });
    }

    static getAll() {

        return http.get(`/dataset/datasets`)
            .then(response => {
                return response;
            });
    }

    static getInstance(instanceID) {
        return http.get(`/dataset/instances/${instanceID}`)
             .then(response => {
                 return response;
             });
    }

    static getVersion(datasetID, edition, version) {
        return http.get(`/dataset/datasets/${datasetID}/editions/${edition}/versions/${version}`)
             .then(response => {
                 return response;
             });
    }

    static getLatestVersion(datasetID) {
        const datasetURL = `/dataset/datasets/${datasetID}`;

        return new Promise(async (resolve, reject) => {
            const dataset = await http.get(datasetURL).catch(error => reject(error));
            
            if (!dataset || !dataset.current || !dataset.current.links.latest_version) {
                resolve();
                return;
            }

            const latestVersionURL = url.resolve(dataset.current.links.latest_version.href);
            const latestVersion = await http.get(`/dataset${latestVersionURL}`).catch(error => reject(error));
            resolve(latestVersion);
        });
    }

    static getVersionDimensions(datasetID, edition, version) {
        return http.get(`/dataset/datasets/${datasetID}/editions/${edition}/versions/${version}/dimensions`)
             .then(response => {
                 return response;
             });
    }

    static updateInstanceDimensions(instanceID, dimensions) {
        const body = {dimensions};
        return http.put(`/instances/${instanceID}`, body);
    }

    static updateDimensionLabelAndDescription(instanceID, dimension, name, description) {
        const body = {
            "label": name,
            "description": description
        }

        return http.put(`/instances/${instanceID}/dimensions/${dimension}`, body, true)
            .then(response => {
                return response;
            });
    }

    static updateVersionMetadata(datasetID, edition, version, metadata) {
        if (typeof metadata !== "object") {
            return Promise.reject({status: 400});
        }
        return http.put(`/dataset/datasets/${datasetID}/editions/${edition}/versions/${version}`, metadata, true)
            .then(response => {
                return response;
            });
    }

    static updateInstanceEdition(instanceID, edition) {
        const body = {
          "edition": edition,
        }
        return http.put(`/dataset/instances/${instanceID}`, body, true)
            .then(response => {
                return response;
            });
    }

    static confirmEditionAndCreateVersion(instanceID, edition, metadata) {
        let body = {
          "edition": edition,
          "state": "edition-confirmed"
        }
        if (metadata && typeof metadata === "object") {
            body = {
                ...body,
                ...metadata
            }
        }
        return http.put(`/dataset/instances/${instanceID}`, body, true);
    }

    static updateDatasetMetadata(datasetID, metadata) {
        return http.put(`/dataset/datasets/${datasetID}`, metadata, true)
            .then(response => {
                return response;
            })
    }

    static getAllInstances() {
        return http.get(`/dataset/instances`)
            .then(response => {
                return response;
            });
    }

    static getCompletedInstances() {
         return http.get(`/dataset/instances?state=completed`)
             .then(response => {
                 return response;
             });
    }

    static getNewVersionsAndCompletedInstances() {
        return http.get(`/dataset/instances?state=completed,edition-confirmed,associated`)
            .then(response => {
                return response;
            });
    }
}

@@ -591,32 +591,226 @@
      %7D);%0A    %7D%0A%0A
+    static getEditions(datasetID) %7B%0A        return http.get(%60/dataset/datasets/$%7BdatasetID%7D/editions%60)%0A             .then(response =%3E %7B%0A                 return response;%0A             %7D);%0A    %7D%0A%0A
     static getVe

Add getEditions method