#ifndef INCLUDED_OPTIONS_
#define INCLUDED_OPTIONS_

#include <string>
#include <fstream>
#include <bobcat/argconfig>

#include "../types/types.h"
#include "../common/common.h"

// see below for the decisions wrt --spool-path

class Options: private Types, private Common
{
    FBB::ArgConfig *d_arg;

    std::string d_configFile;
    bool d_defaultConfig;
    bool d_configExists;

    std::string d_addressesFilename;
    std::ifstream d_addresses;

    std::string d_ccFilename;
    std::ifstream d_ccFile;

    std::string d_spoolPath;

    bool d_keepDir;
    bool d_compile;
    bool d_sendMail;
    bool d_gpg;
    bool d_cc;
    bool d_debug;
    bool d_OK = false;

    bool d_spoolZip;            // store the zip in the spool path
    bool d_pdf;                 // construct the pdf
    
    std::string d_ccAddresses;
    std::string d_rotate;
    std::string d_mailZip;
    std::string d_specs;
    std::string d_latexSkeleton;
    std::string d_subject;
    std::string d_workingDir;
    std::string d_errorDir;
    std::string d_errorURL;
    std::string d_fromAddress;
    std::string d_std;

    bool d_workingDirOption;

    static std::string s_configFile;
    static std::string s_spoolPath;
    static std::string s_latexSkeleton;
    static std::string s_log;
    static std::string s_subject;
    static std::string s_workingDir;
    static std::string s_errorDir;
    static std::string s_errorURL;

    public:
        Options();
        void init();
        void onlyPdf();

        std::ifstream &addresses();
        std::string const &addressesFilename() const;

        std::string const &ccAddresses() const;

        std::ifstream &ccFile();
        std::string const &ccFilename() const;

        std::string const &std() const;

        std::string const &fromAddress() const;

        std::string const &specs() const;
        std::string const &spoolPath() const;
        std::string const &latexSkeleton() const;
        std::string const &rotate() const;

        std::string const &mailZipAddresses() const;

        std::string const &subject() const;
        std::string const &errorDir() const;
        std::string const &errorURL() const;
        std::string const &workingDir() const;
        bool workingDirOption() const;
        void workingDir(char const *dirName);

        bool keepDir() const;
        bool cc() const;
        bool compile() const;
        bool gpg() const;
        bool sendMail() const;
        bool debug() const;
        bool OK() const;
        bool spoolZip() const;
        bool pdf() const;
        void allOK();

        static std::string const &defaultConfigFile();
        static std::string const &defaultLatexSkeleton();
        static std::string const &defaultLog();
        static std::string const &defaultSpoolPath();
        static std::string const &defaultSubject();
        static std::string const &defaultWorkingDir();
        static std::string const &defaultErrorDir();
        static std::string const &defaultErrorURL();

    private:
        void openConfig();
        void verifyConfig() const;
        void openLog() const;
        void setLatexSkeleton();
        void setSubject();
        void setWorkingDir();
        void setSpoolPath();
        void setErrorDirURL();
        std::string setMailZipAddresses();              // .ih
        void spoolActions();
        std::string setAddresses(int option);
};

extern Options g_options;

inline std::string const &Options::ccAddresses() const
{
    return d_ccAddresses;
}

inline std::string const &Options::defaultConfigFile()
{
    return s_configFile;
}

inline std::string const &Options::defaultLatexSkeleton()
{
    return s_latexSkeleton;
}

inline std::string const &Options::defaultLog()
{
    return s_log;
}

inline std::string const &Options::defaultSpoolPath()
{
    return s_spoolPath;
}

inline std::string const &Options::defaultErrorDir()
{
    return s_errorDir;
}

inline std::string const &Options::defaultErrorURL()
{
    return s_errorURL;
}

inline std::string const &Options::defaultSubject()
{
    return s_subject;
}

inline std::string const &Options::defaultWorkingDir()
{
    return s_workingDir;
}

inline std::string const &Options::latexSkeleton() const
{
    return d_latexSkeleton;
}

inline std::string const &Options::mailZipAddresses() const
{
    return d_mailZip;
}
        
inline std::string const &Options::specs() const
{
    return d_specs;
}
        
inline std::string const &Options::rotate() const
{
    return d_rotate;
}
        
inline bool Options::pdf() const
{
    return d_pdf;
}
        
inline bool Options::cc() const
{
    return d_cc;
}
        
inline bool Options::OK() const
{
    return d_OK;
}
        
inline bool Options::spoolZip() const
{
    return d_spoolZip;
}
        
inline void Options::allOK()
{
    d_OK = true;
}
        
inline bool Options::gpg() const
{
    return d_gpg;
}
        
inline bool Options::sendMail() const
{
    return d_sendMail;
}
        
inline std::string const &Options::spoolPath() const
{
    return d_spoolPath;
}
        
inline std::string const &Options::errorDir() const
{
    return d_errorDir;
}
        
inline std::string const &Options::errorURL() const
{
    return d_errorURL;
}
        
inline std::string const &Options::subject() const
{
    return d_subject;
}
        
inline std::string const &Options::workingDir() const
{
    return d_workingDir;
}
        
inline bool Options::workingDirOption() const
{
    return d_workingDirOption;
}
        
inline void Options::workingDir(char const *dirName)
{
    d_workingDir = dirName;
}
        
inline bool Options::keepDir() const
{
    return d_keepDir;
}
        
inline bool Options::compile() const
{
    return d_compile;
}
        
inline std::string const &Options::addressesFilename() const
{
    return d_addressesFilename;
}

inline std::ifstream &Options::addresses()
{
    return d_addresses;
}

inline std::string const &Options::ccFilename() const
{
    return d_ccFilename;
}

inline std::string const &Options::std() const
{
    return d_std;
}

inline std::string const &Options::fromAddress() const
{
    return d_fromAddress;
}

inline std::ifstream &Options::ccFile()
{
    return d_ccFile;
}

inline bool Options::debug() const
{
    return d_debug;
}


//   (0)     (1)     (2)     (3)       actions:    M: mail zip, - no actions
//   spool   spool   mail    pdf       ((1) always suppresses (2)
//   path    zip     zip
// ---------------------------------------------------------------------
//     1       1       1       1        !2, 3->1, 1->0
//     1       1       1       0        !2,       1->0
//     1       1       0       1            3->1, 1->0
//     1       1       0       0                  1->0
//     1       0       1       1       3->0, M
//     1       0       1       0       M
//     1       0       0       1       3->0
//     1       0       0       0       -
//     0       1       1       1       -
//     0       1       1       0       -
//     0       1       0       1       -
//     0       1       0       0       -
//     0       0       1       1       M, !3
//     0       0       1       0       M
//     0       0       0       1       -
//     0       0       0       0       -
// ----------------------------------------------------------------
//  1  -> !2
//  !0 -> !1, !3
//  !3 -> 1 w/o pdf

#endif




