#ifndef STREAKS_H
#define STREAKS_H

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

#include "string.h"
#include "pslib.h"
#include "psmodules.h"
#include "nebclient.h"

#include "streaksextern.h"
#include "streaksastrom.h"

typedef struct {
    psString    resolved_name;
    psString    name;
    bool        inNebulous;
    psFits      *fits;
    int         nHDU;
    psString    extname;
    psMetadata  *header;
    int         numZPlanes;
    psImage     *image;
    psArray     *imagecube;
    pmFPAfile   *pmfile;
    int         numCols;
    int         numRows;
} sFile;


typedef enum {
    IPP_STAGE_NONE = 0,
    IPP_STAGE_RAW,
    IPP_STAGE_CHIP,
    IPP_STAGE_WARP,
    IPP_STAGE_DIFF
} ippStage;


typedef struct {
    pmConfig *config;
    ippStage stage;
    int     extnum;
    int     nHDU;   // number of HDUs in the inputs (all must be equal)
    sFile *inImage;
    sFile *inMask;
    sFile *inWeight;
    sFile *outImage;
    sFile *outMask;
    sFile *outWeight;
    sFile *recImage;
    sFile *recMask;
    sFile *recWeight;
    sFile *inChMask;    // for chip stage input mask is camera mask and output goes to both chip and cam masks
    sFile *outChMask;
    sFile *recChMask;
    psString class_id;
    pmFPAfile  *inAstrom;
    strkAstrom *astrom;
    bool  bilevelAstrometry;
    pmFPAview *view;
    pmChip  *chip;  // current chip
    pmCell  *cell;  // current cell
    psImage *warpedPixels;
    psVector    *tiles;
    double  transparentStreaks;
} streakFiles;

#include "streaksio.h"

extern void setupAstrometry(streakFiles *);
extern strkAstrom *streakSetAstrometry(strkAstrom *, ippStage stage, pmFPA *, pmChip *, bool fromCell, psMetadata *md,
    int numCols, int numRows);
// can't declare this in streaksastrom due to header file ordering
extern void cellToChip(PixelPos *chip, strkAstrom *astrom, PixelPos *cell);

extern bool computeWarpedPixels(streakFiles *sf);
extern void streaksExit(psString, int);
extern ippStage parseStage(psString);
extern psString pathToDirectory(char *path);

#define CHIP_LEVEL_INPUT(_stage) ((_stage == IPP_STAGE_RAW) || (_stage == IPP_STAGE_CHIP))
#define USE_SUPPLIED_ASTROM(_stage) CHIP_LEVEL_INPUT(_stage)

#define SFILE_IS_IMAGE(_sfile) (_sfile->image || _sfile->imagecube)
#define IN_NEBULOUS(_filename) (!strncasecmp(_filename, "neb://", strlen("neb://")))

#endif // STREAKS_H
