package com.atlassian.stash.internal.web.admin;

import com.atlassian.stash.internal.backup.Backup;
import com.atlassian.bitbucket.util.Page;
import com.atlassian.bitbucket.util.PageRequest;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;

import java.util.LinkedHashMap;

//TECH DEBT: This should ideally use RestPage from the bitbucket-rest-model module
public class RestBackupPage extends LinkedHashMap<String, Object> {

    public RestBackupPage(Page<Backup> page) {
        put("start", page.getStart());
        put("limit", page.getLimit());
        put("size", page.getSize());
        put("isLastPage", page.getIsLastPage());
        put("values", Iterables.transform(page.getValues(), new Function<Backup, RestBackup>() {

            @Override
            public RestBackup apply(Backup backup) {
                return new RestBackup(backup);
            }
        }));

        PageRequest next = page.getNextPageRequest();
        if (next != null) {
            put("nextPageStart", next.getStart());
        }
    }
}
