package org.nuiton.scmwebeditor;

import org.nuiton.scmwebeditor.actions.*;

public interface ScmConnectionInterface {

    /**
     * Searches the repository's files to make a list of them
     * @param action the SearchAction which contains the parameters (repository's address, username, password...)
     *               and which will contain the result (a list of TreeNode for example)
     * @return SearchAction.AUTH_ERROR if there has been a problem during the authentication
     *         SearchAction.ROOT if the result is the root of the repository
     *         SearchAction.SUCCESS otherwise
     */
    public String search(SearchAction action);


    /**
     * Makes a commit of the changed made to the edited file
     * @param action the ScmWebEditorCommitAction which contains the parameters (repository's address, username,
     *               password, new file content...) and which will contain the result (new revision number,
     *               information message...)
     * @return ScmWebEditorCommitAction.ERROR if an error occurred
     *         ScmWebEditorCommitAction.LOGIN if the authentication failed
     *         ScmWebEditorCommitAction.ERROR_PATH if it is impossible to reach the repository
     *         ScmWebEditorCommitAction.FILE_MODIFY if the local file has been modified by another program
     *         ScmWebEditorCommitAction.SUCCESS if the commit has been done without any problem
     */
    public String commit(ScmWebEditorCommitAction action);


    /**
     * Cancels all the changes made on the edited file by getting its last revision
     * @param action the ResetAction which contains the parameters (repository's address, username, password...)
     *               and which will contain the result (the last revision's content and the revision number)
     * @return ResetAction.AUTH_ERROR if the authentication failed
     *         ResetAction.ERROR_PATH if it is impossible to reach the repository
     *         ResetAction.SUCCESS if the reset has been done without any problem
     */
    public String reset(ResetAction action);


    /**
     * Logs the user out of the current SCM
     * @param action the LogoutAction which contains the parameters (repository's address, servlet request, SCM session...)
     * @return LogoutAction.SUCCESS if the logout has been done without any problem
     */
    public String logout(LogoutAction action);


    /**
     * Uploads a file to the repository as a new file
     * @param action the UploadAction which contains the parameters (repository's address, file to upload...)
     * @return UploadAction.ERROR if an error occurred
     *         UploadAction.REDIRECT if there is no file to upload
     *         UploadAction.LOGIN if the authentication failed
     *         UploadAction.SUCCESS if the upload has been done without any problem
     */
    public String uploadFile(UploadAction action);


    /**
     * Gives the content of a file as a String
     * @param path the path to the file to get the content from
     * @param username the user's login for the SCM
     * @param password the user's password for the SCM
     * @return a String which contains the file's content
     */
    public String getFileContent(String path, String username, String password);


    /**
     * Gives the number of the head revision
     * @param path the path to the SCM
     * @param username the user's login for the SCM
     * @param password the user's password for the SCM
     * @return a String which contains the head revision's number
     */
    public String getHeadRevisionNumber(String path, String username, String password);

}
