package com.atlassian.bitbucket.internal.mirroring.mirror.nav;

import com.atlassian.bitbucket.mirroring.mirror.UpstreamServer;

import javax.annotation.Nonnull;

/**
 * @since 4.2
 */
public interface MirroringNavBuilder {

    @Nonnull
    String buildAbsolute();

    @Nonnull
    CloudUpstreamNavBuilder cloudUpstream(@Nonnull UpstreamServer upstream);

    @Nonnull
    Rest rest();

    /**
     * @param upstream the upstream to create the url for.
     * @return a builder for the URL to the configuration page of the mirror. This page is not meant to be consumed by
     *         the users but rather by the upstream in its UI.
     */
    @Nonnull
    MirroringUrl mirrorConfig(@Nonnull UpstreamServer upstream);

    /**
     * @return a builder for the URL to the placeholder page of the mirror
     */
    @Nonnull
    MirroringUrl placeholder();

    @Nonnull
    ServerUpstreamNavBuilder serverUpstream(@Nonnull UpstreamServer upstream);

    @Nonnull
    MirroringUrl stp(@Nonnull UpstreamServer upstream);

    @Nonnull
    UpstreamNavBuilder upstream(@Nonnull UpstreamServer upstream);

    interface Rest {
        @Nonnull
        UpstreamServerRest upstreamServer(@Nonnull String upstreamId);
    }

    interface UpstreamServerRest extends MirroringUrl {
        @Nonnull
        AddonRest addon();

        /**
         * Returns a template URL that the upstream will call to get information on a mirrored repo. The
         * upstream will substitute parameters within the URL with local context to produce the final URL.
         *
         * <p>This method will not generate a valid URL. Its template that has to be parsed and processed by cloud.
         * Specifically, the template parameters are not URL encoded so that cloud can match them.</p>
         *
         * @return the template URL for the resource.
         */
        @Nonnull
        MirroringUrl templateRepoUrl();
    }

    interface AddonRest extends MirroringUrl {
        @Nonnull
        MirroringUrl descriptor();
        @Nonnull
        MirroringUrl events();
        @Nonnull
        MirroringUrl installedHook();
        @Nonnull
        MirroringUrl uninstalledHook();
    }
}
