use strict;
use warnings;

our @ScripActions = (
    { Name        => 'Send Forward',
      Description => 'Send forwarded message',
      ExecModule  => 'SendForward', },
);

our @Scrips = (
    {  Description    => 'On Forward Transaction Send forwarded message',
       ScripCondition => 'On Forward Transaction',
       ScripAction    => 'Send Forward',
       Template       => 'Forward' },
    {  Description    => 'On Forward Ticket Send forwarded message',
       ScripCondition => 'On Forward Ticket',
       ScripAction    => 'Send Forward',
       Template       => 'Forward Ticket' },
);

our @Initial = (
    sub {
        my $forward_template = RT::Template->new(RT->SystemUser);
        $forward_template->Load('Forward');
        $forward_template->SetDescription('Forwarded message');

        if ( $forward_template->Content =~
                m/^\n*This is (a )?forward of transaction #\{\s*\$Transaction->id\s*\} of (a )?ticket #\{\s*\$Ticket->id\s*\}\n*$/
            ) {
            $forward_template->SetContent(q{

{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of transaction #".$Transaction->id." of ticket #". $Ticket->id }
});
        }
        else {
            RT->Logger->error('Current "Forward" template is not the default version, please check docs/UPGRADING-4.2');
        }

        my $forward_ticket_template = RT::Template->new(RT->SystemUser);
        $forward_ticket_template->Load('Forward Ticket');
        $forward_ticket_template->SetDescription('Forwarded ticket message');
        if ( $forward_ticket_template->Content eq q{

This is a forward of ticket #{ $Ticket->id }
} ) {
            $forward_ticket_template->SetContent(q{

{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of ticket #". $Ticket->id }
});

        }
        else {
            RT->Logger->error('Current "Forward Ticket" template is not the default version, please check docs/UPGRADING-4.2');
        }
    },
);
