#include "streaksremove.h"

int
main(int argc, char *argv[])
{
    pmConfig *config = pmConfigRead(&argc, argv, NULL);
    if (!config) {
        psErrorStackPrint(stderr, "failed to parse arguments\n");
        exit(PS_EXIT_CONFIG_ERROR);
    }

    char *fileName = argv[1];
    if (!fileName) {
        fprintf(stderr, "Usage: %s filename\n", argv[0]);
        exit(PS_EXIT_DATA_ERROR);
    }

    psFits *fits = psFitsOpen(fileName, "r");
    if (!fits) {
        psError(PS_ERR_UNKNOWN, false, "failed to open fits file: %s\n", fileName);
        psErrorStackPrint(stderr, "");
        exit(PS_EXIT_DATA_ERROR);
    }

    psMetadata *header = psFitsReadHeader(NULL, fits);
    if (!header) {
        psError(PS_ERR_IO, false, "failed to read header for: %s", fileName);
        psErrorStackPrint(stderr, "");
        exit(PS_EXIT_DATA_ERROR);
    }

    bool mdok;
    bool isDestreaked = psMetadataLookupBool(&mdok, header, "PSDESTRK");
    if (mdok && isDestreaked) {
        printf("%s is a destreaked file\n", fileName);
        exit(0);
    } else {
        printf("%s is not a destreaked file\n", fileName);
        exit(42);
    }
}
