//---------------------------------------------------------------------------------
// <copyright file="LqrSMACIFileSetSettings.h" company="LiquidRobotics">
//
// Copyright (c) 2014 Liquid Robotics, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// This software is associated with a release.  Liquid Robotics makes no
// representation that the design, interfaces or component distribution will
// remain unchanged in future releases.
//
// </copyright>
//
// <summary>
//   Declarations for the IFileSetSettings purely-abstract class, which defines the
//   format of the FileSetSettings class and standardizes the interface.
// </summary>
//
// <owner>Mike Cookson</owner>
//---------------------------------------------------------------------------------

#ifndef __LQRSMACIFILESETSETTINGS_H__
#define __LQRSMACIFILESETSETTINGS_H__

#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LqrSMACSharedLib.h"

namespace LiquidRobotics {
namespace SMACFramework {

class SHARED_LIB_PUBLIC IFileSetSettings
{
public:

    typedef unsigned FileSizeType;
    typedef unsigned SizeType;
    typedef std::string string;
	typedef boost::posix_time::time_duration TimeSpan;

    enum ECompressionType
    {
        ECT_NONE,           // data files are compressed when it is archived
        ECT_BZIP2,          // data files are compressed using bzip2 when it is archived
        ECT_GZIP            // data files are compressed using gzip when they are archived
    };

    enum EPurgeStrategy
    {
        EPS_NONE,           // archive files are never purged: when the size is reached, writes fail
        EPS_OLDEST          // archive files with the oldest files modification times are deleted
    };

    static string CompressionTypeToString(ECompressionType ct);
    static ECompressionType CompressionTypeFromString(const string& str);
    static string PurgeStrategyToString(EPurgeStrategy ps);
    static EPurgeStrategy PurgeStrategyFromString(const string& str);

    virtual ~IFileSetSettings() { }

    // ArchiveCompressionType configures whether and how the currently-accumulating
    // data file is compressed once it reaches its maximum size; the compression type
    // affects the extension of the file
    virtual ECompressionType GetArchiveCompressionType() const = 0;
    virtual void SetArchiveCompressionType(ECompressionType newValue) = 0;

    // ArchiveDirectory is the directory where archives are stored; if blank or if
    // the named directory does not exist and cannot be created, files are stored in
    // WorkingDirectory
    virtual const string& GetArchiveDirectory() const = 0;
    virtual void SetArchiveDirectory(const string& newValue) = 0;

    // Extension is appended to the prefix and any additional characters when creating
    // files
    virtual const string& GetExtension() const = 0;
    virtual void SetExtension(const string& newValue) = 0;

    // KeepWritesTogether determines if file writes are always made to a file without
    // being subdivided (true) or if file writes can be split across files (false)
    virtual bool GetKeepWritesTogether() const = 0;
    virtual void SetKeepWritesTogether(bool newValue) = 0;

    // MaxBytesQueue determines the number of bytes that can be held between the caller's
    // thread and the file write thread without causing hte calling to block; if the number
    // is zero, there is no background thread spawned.
    virtual SizeType GetMaxBytesQueued() const = 0;
    virtual void SetMaxBytesQueued(SizeType newValue) = 0;

    // MaxFileSize is the maximum number of bytes that can be written to a single file in
    // the set before compression; at least one write will be made in its entirety, even
    // if the maximum file size is too small.
    virtual FileSizeType GetMaxFileSize() const = 0;
    virtual void SetMaxFileSize(FileSizeType newValue) = 0;

    // MaxFiles determines the maximum number of files (current working file + archives) that
    // will be retained.
    virtual SizeType GetMaxFiles() const = 0;
    virtual void SetMaxFiles(SizeType newValue) = 0;

    // MaxRetainTime is the maximum time to retain files; a zero-length retain time is ignored
    virtual TimeSpan GetMaxRetainTime() const = 0;
    virtual void SetMaxRetainTime(TimeSpan newValue) = 0;

    // Prefix is the first part of the filename that will be used for working files and archives
    virtual const string& GetPrefix() const = 0;
    virtual void SetPrefix(const string& newValue) = 0;

    // PurgeStrategy defines whether and how old archive files are purged
    virtual EPurgeStrategy GetPurgeStrategy() const = 0;
    virtual void SetPurgeStrategy(EPurgeStrategy newValue) = 0;

    // WorkingDirectory is where data files are accumulated and the default
    // directory for archives if ArchiveDirectory is blank or not usable
    virtual const string& GetWorkingDirectory() const = 0;
    virtual void SetWorkingDirectory(const string& newValue) = 0;
};

}
}

#endif // __LQRSMACIFILESETSETTINGS_H__
