#!/usr/bin/env perl

use v5.14;
use warnings;

BEGIN {
    use File::Basename qw(dirname);
    use File::Spec;
    my $d = dirname(File::Spec->rel2abs($0));
    require "$d/../setenv.pl";
}

use Getopt::Long;
use FixMyStreet::Script::Inactive;
use Pod::Usage;

my %h;
GetOptions(\%h,
    'anonymize=s' => \&time_check,
    'close=s' => \&time_check,
    'delete=s' => \&time_check,
    'category=s',
    'state=s',
    'cobrand=s', 'verbose|v', 'help|h', 'dry-run|n') or exit 1;
pod2usage(0) if $h{help};
pod2usage(1) unless $h{anonymize} || $h{close} || $h{delete};

FixMyStreet::Script::Inactive->new(%h)->reports;

sub time_check {
    my ($name, $value) = @_;
    die "\u$name time not in correct format\n" unless $value =~ /^\d+(m|d)?$/;
    $h{$name} = $value;
}

__END__

=head1 NAME

process-inactive-reports - deal with anonymizing inactive non-open reports

=head1 SYNOPSIS

process-inactive-reports [--anonymize N] [--close N] [--delete N] [--cobrand COBRAND]
  [--category CATEGORY] [--state STATE]

 Options:
   --anonymize   Anonymize non-open reports (and related) inactive longer than this time
   --close       Close comments on non-open reports inactive longer than this time
   --delete      Delete non-open reports inactive longer than this time
   --cobrand     Only act upon reports made on this cobrand
   --category    Only act upon reports made in this category
   --state       Only act upon reports in this state
   --dry-run     Don't actually anonymize anything or send any emails
   --verbose     Output as to which reports are being affected
   --help        This help message

Times without a suffix or with an "m" suffix are a number of months, and you
can specify days with a "d" suffix.

=cut
