package com.atlassian.bitbucket.internal.integration.jira.rest;

import com.atlassian.bitbucket.integration.jira.JiraIssue;
import com.atlassian.bitbucket.internal.integration.jira.SimpleJiraIssue;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import com.atlassian.bitbucket.rest.RestMapEntity;
import com.google.common.collect.Sets;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import java.util.Set;
import java.util.function.Function;

@JsonSerialize
@JsonSurrogate(JiraIssue.class)
public class RestJiraIssue extends RestMapEntity {

    public static final Function<JiraIssue, RestJiraIssue> REST_TRANSFORM = RestJiraIssue::new;

    @SuppressWarnings("unused")
    public RestJiraIssue() {
    }

    public RestJiraIssue(JiraIssue issue) {
        put("key", issue.getKey());
        put("url", issue.getUrl());
    }

    // REST Documentation Examples
    private static final RestJiraIssue[] exampleIssues = {
        new RestJiraIssue(new SimpleJiraIssue("JRA-9", "https://jira.atlassian.com/browse/JRA-9")),
        new RestJiraIssue(new SimpleJiraIssue("JRA-11", "https://jira.atlassian.com/browse/JRA-11")),
    };
    public static final Set<RestJiraIssue> RESPONSE_SET_EXAMPLE = Sets.newHashSet(exampleIssues);
}
