#ifndef PP_MOPS_H
#define PP_MOPS_H

#include <pslib.h>
#include <pmSourceMasks.h>

#define IN_EXTNAME "SkyChip.psf"        // Extension name for data in input
#define OBSERVATORY_CODE "F51"          // IAU Observatory Code

// Configuration data
typedef struct {
    psArray *input;                     // Input filenames
    psString exp_name;                  // Exposure name
    psS64 exp_id;                       // Exposure identifier
    psS64 chip_id;                      // Chip stage identifier
    psS64 cam_id;                       // Camera stage identifier
    psS64 fake_id;                      // Fake stage identifier
    psS64 warp_id;                      // Warp stage identifier
    psS64 diff_id;                      // Diff stage identifier
    bool positive;                      // Sense of subtraction, T=positive, F=negative
    float zp, zpErr;                    // Magnitude zero point and error
    float rmsAstrom;                    // Astrometric solution RMS
    psString output;                    // Output filename
} ppMopsArguments;

/// Parse arguments
ppMopsArguments *ppMopsArgumentsParse(int argc, char *argv[]);

typedef struct {
    psString component;                 // Component name
    psMetadata *header;                 // FITS header (extension names *.hdr)
    psString raBoresight, decBoresight; // RA,Dec of telescope boresight
    psString filter;                    // Filter for exposure
    float airmass;                      // Airmass of exposure
    float exptime;                      // Exposure time
    double posangle;                    // Position angle
    double alt, az;                     // Telescope altitude and azimuth
    double mjd;                         // Modified Julian Date of exposure mid-point
    float seeing;                       // Seeing of exposure
    int naxis1, naxis2;                 // Size of image
    long num;                           // Number of detections
    psMetadata *psfHeader;              // FITS header (extension names *.psf)
    psMetadata *table;                  // Columns of data
    psVector *x, *y;                    // Image coordinates
    psVector *ra, *dec;                 // Sky coordinates
    psMetadata *deteffHeader;           // Detection efficiency header (extension names *.deteff)
    psMetadata *deteffTable;            // Detection efficiency table
} ppMopsDetections;

// Allocator
ppMopsDetections *ppMopsDetectionsAlloc(void);

/// Read detections
psArray *ppMopsRead(const ppMopsArguments *args);

/// Purge duplicate detections
bool ppMopsPurgeDuplicates(const psArray *detections);

/// Write detections
bool ppMopsWrite(const psArray *detections, const ppMopsArguments *args);

#endif
