//------------------------------------------------------------------------------------
// <copyright file="LqrSMACIFileSetSettings.cpp" 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>
//   Implementations for the IFileSetSettings purely-abstract class, which defines the
//   format of the FileSetSettings class and standardizes the interface.
// </summary>
//
// <owner>Mike Cookson</owner>
//------------------------------------------------------------------------------------

#include "LqrSMACIFileSetSettings.h"
#include <stdexcept>
#include <sstream>
#include <boost/algorithm/string.hpp>

using namespace std;

static const string BZIP2 = "BZIP2";
static const string GZIP = "GZIP";
static const string NONE = "NONE";
static const string OLDEST = "OLDEST";

namespace LiquidRobotics {
namespace SMACFramework {

IFileSetSettings::string IFileSetSettings::CompressionTypeToString(ECompressionType ct)
{
    string result;

    switch(ct)
    {
    case ECT_BZIP2:     result = BZIP2;   break;
    case ECT_GZIP:      result = GZIP;    break;
    case ECT_NONE:      result = NONE;    break;

    default:
        {
            stringstream stm;
            stm << "ECompressType does not have an enumerated value of " << (int) ct;
            throw invalid_argument(stm.str());
        }
    }

    return result;
}

IFileSetSettings::ECompressionType IFileSetSettings::CompressionTypeFromString(const string& str)
{
    ECompressionType result = ECT_NONE;

    if (boost::iequals(str, BZIP2))
        result = ECT_BZIP2;
    else if (boost::iequals(str, GZIP))
        result = ECT_GZIP;
    else if (!boost::iequals(str, NONE))
    {
        stringstream stm;
        stm << "ECompressType has no match for '" << str << "'";
        throw invalid_argument(stm.str());
    }

    return result;
}

IFileSetSettings::string IFileSetSettings::PurgeStrategyToString(EPurgeStrategy ps)
{
    string result;

    switch(ps)
    {
    case EPS_NONE:      result = NONE;    break;
    case EPS_OLDEST:    result = OLDEST;  break;

    default:
        {
            stringstream stm;
            stm << "EPurgeStrategy does not have an enumerated value of " << (int) ps;
            throw invalid_argument(stm.str());
        }
    }

    return result;
}

IFileSetSettings::EPurgeStrategy IFileSetSettings::PurgeStrategyFromString(const string& str)
{
    EPurgeStrategy result = EPS_NONE;

    if (boost::iequals(str, OLDEST))
        result = EPS_OLDEST;
    else if (!boost::iequals(str, NONE))
    {
        stringstream stm;
        stm << "EPurgeStrategy has no match for '" << str << "'";
        throw invalid_argument(stm.str());
    }

    return result;
}

}
}
