package com.atlassian.bitbucket.internal.mirroring.upstream.rest;

import com.atlassian.bitbucket.internal.mirroring.upstream.SimpleMirrorServer;
import com.atlassian.bitbucket.mirroring.upstream.MirrorServer;
import com.atlassian.bitbucket.rest.RestLinkedMapEntity;
import com.atlassian.bitbucket.rest.util.RestNamedLink;
import com.atlassian.bitbucket.rest.util.RestRelatedLinks;

import java.util.Date;

public class RestMirroredRepositoryDescriptor extends RestLinkedMapEntity {

    private final String MIRROR_SERVER = "mirrorServer";
    private final String RELATIONSHIP_SELF = "self";

    RestMirroredRepositoryDescriptor(MirrorServer mirrorServer, String selfLink) {
        put(MIRROR_SERVER, new RestMirrorServer(mirrorServer));
        if (selfLink != null) {
            setLinks(new RestRelatedLinks.Builder()
                    .addRelatedLink(RELATIONSHIP_SELF, new RestNamedLink(selfLink))
                    .build());
        }
    }

    // REST Documentation
    public static final RestMirroredRepositoryDescriptor EXAMPLE =
            new RestMirroredRepositoryDescriptor(new SimpleMirrorServer.Builder()
                    .baseUrl("https://us-east.bitbucket.example.com")
                    .lastSeenDate(new Date())
                    .mirror("BSERV-1337-ABCD-R2D2-C3P0", "US East Mirror")
                    .product("Bitbucket Server", "4.2.0")
                    .enabled(true)
                    .build(), "https://us-east.bitbucket.example.com/rest/mirroring/1.0/repos/1?jwt=eyJhbGciOiJIUz" +
                    "I1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9." +
                    "TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ");
}
