#include <Ice/Ice.h>
#include <IceUtil/Optional.h>
#include "./fitsFileI.hpp"
//#include "dataManager.h"

using namespace std;

int
main(int argc, char* argv[])
{
    int status = 0;
    Ice::CommunicatorPtr ic;
    std::string filename = "SHARKNIR.{:0>4d}{:0>2d}{:0>2d}.{:0>5d}.{:s}.fits";
    std::string outFilename = "";
    IceUtil::Optional<std::string> comment;

    try {
        ic = Ice::initialize(argc, argv);
        Ice::ObjectPrx base = ic->stringToProxy("dataManagerAdapter:default -p 10501");
        sharknir::dataManager::fitsFilePrx archiver = sharknir::dataManager::fitsFilePrx::checkedCast(base);
        if (!archiver)
            throw "Invalid proxy";
        std::cout << filename << std::endl;
        status = archiver->createEmptyFile(filename, IceUtil::None, outFilename);
        if (status == 0)
          {
            std::cout << "Filename of new file is " << outFilename << std::endl;
            comment = IceUtil::None;
            status = archiver->printFITS(outFilename, "ORIGIN", "MGIO-LBT", comment);
          }
    } catch (const Ice::Exception& ex) {
        cerr << ex << endl;
        status = 1;
    } catch (const char* msg) {
        cerr << msg << endl;
        status = 1;
    }
    if (ic)
        ic->destroy();

    cout << status << endl;
    return status;
}
