package com.atlassian.bitbucket.rest.user;

import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import com.atlassian.bitbucket.rest.RestMapEntity;
import com.atlassian.bitbucket.rest.util.RestPage;
import com.atlassian.bitbucket.user.DetailedGroup;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import java.util.function.Function;

import static com.atlassian.bitbucket.rest.util.RestDocUtils.pageOf;

@JsonSerialize
@JsonSurrogate(DetailedGroup.class)
public class RestDetailedGroup extends RestMapEntity {

    public static final Function<String, RestDetailedGroup> NAME_TRANSFORM = RestDetailedGroup::new;
    public static final Function<DetailedGroup, RestDetailedGroup> REST_TRANSFORM = RestDetailedGroup::new;

    public RestDetailedGroup(DetailedGroup group) {
        this(group.getName(), group.isDeletable());
    }

    public RestDetailedGroup(String group) {
        this(group, false);
    }

    // Required for REST documentation
    private RestDetailedGroup(String group, boolean deletable) {
        put("name", group);
        put("deletable", deletable);
    }

    // REST Documentation Examples

    public static final RestDetailedGroup RESPONSE_EXAMPLE = new RestDetailedGroup("group-a", true);

    public static final RestPage<RestDetailedGroup> PAGE_EXAMPLE = pageOf(RESPONSE_EXAMPLE);

}
