//
// Created by Tristan Juricek on 9/19/15.
//

#ifndef FSCLIENT_WORKSPACE_H
#define FSCLIENT_WORKSPACE_H

#include <chrono>
#include <string>

#include "Notification.h"

class WorkspaceImpl;

// Manages access to the Perforce workspace we're editing via the mirror.
//
// This handles an intelligent call to p4 reconcile.
class Workspace
{
public:
    ~Workspace();

    Workspace();

    Workspace(const std::string & workspace);

    // The local directory location that is the root of our Perforce workspace
    void
    setWorkspace(std::string & w)
    {
        _workspace = w;
    }

    // The local directory location that is the root of our Perforce workspace
    const std::string &
    workspace() const
    {
        return _workspace;
    }

    // Convert the relative path to the absoluite local directory location
    // underneath the Perforce workspace
    std::string
    path(const std::string & p) const;

    // Use this specific changelist number instead of the default changelist
    // for calls to p4 reconcile.
    void
    setChangelist(const std::string & c);

    // Use this specific changelist number instead of the default changelist
    // for calls to p4 reconcile.
    const std::string &
    changelist() const;

    // The time we wait from the last file operation to trigger p4 reconcile.
    int
    pauseAmount() const;

    // The time we wait from the last file operation to trigger p4 reconcile.
    void
    setPauseAmount(int t);

    // If true, the workspace is churning
    bool
    processing() const;

    // Debugging status for the last operations
    std::string
    status();

    void
    enqueue(const Notification & n);

    //-----------------------------------------------------------------------
    // Failure codes
    //-----------------------------------------------------------------------

    static const int CONNECTION_FAILURE = -1;
    static const int COMMAND_FAILURE = -2;

private:
    std::string _workspace;

    WorkspaceImpl *_impl;
};


#endif //FSCLIENT_WORKSPACE_H
