#!/bin/env perl
###
###     Tests for the PStamp module
###

use warnings;
use strict;


use Getopt::Long qw( GetOptions );
use PStamp::Job qw( :standard );

use PS::IPP::Config qw( :standard );
my $ipprc = PS::IPP::Config->new(); # IPP Configuration

my $verbose;
my $image_db;
my $req_type;
my $img_type;
my $id;
my $class_id;
my $x;
my $y;
my $mjd_min;
my $mjd_max;
my $filter;



GetOptions(
    'dbname=s'  =>  \$image_db,
    'req_type=s'=>  \$req_type,
    'img_type=s'=>  \$img_type,
    'id=s'      =>  \$id,
    'class_id=s'=>  \$class_id,
    'x=s'       =>  \$x,
    'y=s'       =>  \$y,
    'mjd_min=s' =>  \$mjd_min,
    'mjd_max=s' =>  \$mjd_max,
    'filter=s'  =>  \$filter,
    'verbose'   =>  \$verbose,
);

my $err = "";
$err .= " --req_type is required" if !$req_type;
$err .= " --img_type is required" if !$img_type;
$err .= " --id is required" if ($req_type ne "bycoord") && !$id;
$err .= " --dbname is required" if !$image_db;

if ($err) {
    print STDERR "$err\n";
    exit $PS_EXIT_DATA_ERROR;
}

my $results = locate_images($ipprc, $image_db, $req_type, $img_type, $id, $class_id,
            $x, $y, $mjd_min, $mjd_max, $filter, $verbose);

foreach my $i (@$results) {
    print "${img_type}_id: $id";
    if ($i->{exp_id}) {
        print " exp_id $i->{exp_id}\n"
    } else {
        print "\n";
    }
    print "\timage:  $i->{image}\n";
    print "\tmask:   $i->{mask}\n"   if $i->{mask};
    print "\tweight: $i->{weight}\n" if $i->{weight};
    print "\tastrom: $i->{astrom}\n" if $i->{astrom};
}

exit 0;

