#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <pslib.h>
#include <psmodules.h>

#include "ppStack.h"

pmPSF *ppStackPSF(const pmConfig *config, int numCols, int numRows, const psArray *psfs)
{
    // Get the recipe values
    int psfInstances = psMetadataLookupS32(NULL, config->arguments, "PSF.INSTANCES"); // Number of instances for PSF
    float psfRadius = psMetadataLookupF32(NULL, config->arguments, "PSF.RADIUS"); // Radius for PSF
    const char *psfModel = psMetadataLookupStr(NULL, config->arguments, "PSF.MODEL"); // Model for PSF
    int psfOrder = psMetadataLookupS32(NULL, config->arguments, "PSF.ORDER"); // Spatial order for PSF

    // Solve for the target PSF
    pmPSF *psf = pmPSFEnvelope(numCols, numRows, psfs, psfInstances, psfRadius, psfModel,
                               psfOrder, psfOrder);
    if (!psf) {
        psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF.");
        return NULL;
    }

    return psf;
}
