package SVN::Hooks::MultiNotify;

use strict;
use warnings;
use SVN::Hooks;

use Exporter qw/import/;
my $HOOK = 'MULTI_NOTIFY';
our @EXPORT = qw/MULTI_NOTIFY_DEFAULTS MULTI_NOTIFY/;

our $VERSION = $SVN::Hooks::VERSION;


sub MULTI_NOTIFY_DEFAULTS {
    my %opt_defaults = @_;
    my $conf = $SVN::Hooks::Confs->{$HOOK};
    $conf->{defaults} = \%opt_defaults;

    return 1;
}


sub MULTI_NOTIFY {
    my $conf = $SVN::Hooks::Confs->{$HOOK};
    push @{$conf->{opts}}, @_;
    $conf->{'post-commit'} = \&post_commit;

    return 1;
};

$SVN::Hooks::Inits{$HOOK} = sub {
    return { defaults => {}, opts => [] };
};

sub post_commit {
    my ($self, $svnlook) = @_;

    require SVN::Notify::Config;

    my @opt_set = @{$self->{opts}};
    for my $ii (0 .. $#opt_set) {
      my $opt_set = $opt_set[$ii];
      warn "going to load $opt_set";
      my $notifier = SVN::Notify::Config->new(
					      $opt_set,
					     );
      $notifier->prepare;
      $notifier->execute(
			 repos_path => $svnlook->repo(),
			 revision   => $svnlook->rev(),
			);
    }
    return;
}



1; # End of SVN::Hooks::Notify
