#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) {
        psErrorStackPrint(stderr, "failed to open fits file: %s\n", fileName);
        exit(PS_EXIT_DATA_ERROR);
    }

    psMetadata *header = psFitsReadHeader(NULL, fits);
    if (!header) {
        psErrorStackPrint(stderr, "failed to read header for: %s", fileName);
        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);
    }
}
