#include "ppbgrestore.h"

ppbgrestoreOptions *ppbgrestoreParseCamera(pmConfig *config)
{
    ppbgrestoreOptions *options = psAlloc(sizeof(*options));
    bool status;

    memset(options, 0, sizeof(*options));

    pmFPAfile *input = pmFPAfileDefineFromArgs(&status, config, "PPBGRESTORE.INPUT", "INPUT");
    if (!input) {
        psFree(options);
        psError(PS_ERR_UNKNOWN, false, "failed to define input file");
        return NULL;
    }
    pmFPAfile *backmdl = pmFPAfileDefineFromArgs(&status, config, "PPBGRESTORE.BACKMDL", "BACKMDL");
    if (!backmdl) {
        psFree(options);
        psError(PS_ERR_UNKNOWN, false, "failed to define background model file");
        return NULL;
    }
    // pmFPAfile *outImage = pmFPAfileDefineOutput(config, input->fpa, "PPBGRESTORE.OUTPUT");
    pmFPAfile *outImage = pmFPAfileDefineOutput(config, input->fpa, "PPBGRESTORE.OUTPUT");
    if (!outImage) {
        psError(PS_ERR_IO, false, _("Unable to generate output file from PPBGRESTORE.OUTPUT"));
        psFree(options);
        return NULL;
    }
    // pmFPAfile *outBG = pmFPAfileDefineOutput(config, NULL, "PPBGRESTORE.BACKGROUND");
    pmFPAfile *outBG = pmFPAfileDefineFromFPA(config, input->fpa, 1, 1, "PPBGRESTORE.BACKGROUND");
    if (!outBG) {
        psError(PS_ERR_IO, false, _("Unable to generate bacgkround file from PPBGRESTORE.BACKGROUND"));
        psFree(options);
        return NULL;
    }

    return options;
}
