package com.atlassian.stash.internal;

import com.atlassian.bitbucket.comment.Comment;
import com.atlassian.bitbucket.commit.CommitDiscussion;
import com.atlassian.stash.internal.comment.InternalComment;
import com.atlassian.stash.internal.commit.InternalCommitDiscussion;
import com.atlassian.stash.internal.project.InternalProject;
import com.atlassian.stash.internal.pull.InternalPullRequest;
import com.atlassian.stash.internal.pull.InternalPullRequestParticipant;
import com.atlassian.stash.internal.repository.InternalRepository;
import com.atlassian.stash.internal.task.InternalTask;
import com.atlassian.stash.internal.user.InternalApplicationUser;
import com.atlassian.stash.internal.user.StashUserAuthenticationToken;
import com.atlassian.bitbucket.project.Project;
import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.pull.PullRequestParticipant;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.task.Task;
import com.atlassian.bitbucket.user.ApplicationUser;

/**
 * Internal utility to recover the internal instances of various interfaces
 */
public class InternalConverter {

    public static InternalComment convertToInternalComment(Comment comment) {
        return (InternalComment) comment;
    }

    public static InternalCommitDiscussion convertToInternalCommitDiscussion(CommitDiscussion commitDiscussion) {
        return (InternalCommitDiscussion) commitDiscussion;
    }

    public static InternalProject convertToInternalProject(Project project) {
        return (InternalProject) project;
    }

    public static InternalPullRequestParticipant convertToInternalParticipant(PullRequestParticipant participant) {
        return (InternalPullRequestParticipant) participant;
    }

    public static InternalPullRequest convertToInternalPullRequest(PullRequest pullRequest) {
        return (InternalPullRequest) pullRequest;
    }

    public static InternalRepository convertToInternalRepository(Repository repository) {
        return (InternalRepository) repository;
    }

    public static InternalTask convertToInternalTask(Task task) {
        return (InternalTask) task;
    }

    public static InternalApplicationUser convertToInternalUser(ApplicationUser user) {
        ApplicationUser stashUser = user;
        if (stashUser instanceof StashUserAuthenticationToken) {
            stashUser = ((StashUserAuthenticationToken) user).getPrincipal();
        }
        return (InternalApplicationUser) stashUser;
    }
}
