#!/usr/bin/perl

use Getopt::Long;

use lib '/app/tools/common/lib';
use Common::Log;
use Common::Amazon::Mail;

use strict;
use warnings;

# variables for command options.
my $filePath;
my $fileName;
my $fileDate;

# program starts here.

# gets command options.
getOptions();

usage("missing file path") unless ( defined $filePath );
usage("missing file name") unless ( defined $fileName );
usage("missing file date") unless ( defined $fileDate );

## add or change email list here
my $recipients = [ qw/
    amy.lehrman@royaltyshare.com
    cbreindel@theorchard.com
    cheryl@royaltyshare.com
    jgasson@theorchard.com
    Royaltyshareinvoices@theorchard.com
    steve@royaltyshare.com
/ ];

# send an email about with the report
my $mail = Common::Amazon::Mail->new;
$mail->to($recipients);
$mail->cc('sysadmin@royaltyshare.com');
$mail->subject("DTMV Billing Report $fileDate");
$mail->body("Here it is.  Enjoy!\n\n");
$mail->sendit( [ $filePath . "/" . $fileName ] );

sub getOptions {

    # p - file path
    # n - file name
    # d - file date
    GetOptions(
        "path|p=s" => \$filePath,
        "name|n=s" => \$fileName,
        "date|d=s" => \$fileDate
    ) or exit;
}
