#!/usr/bin/perl

use strict;
use warnings;
#use Pod::Usage;
#use Getopt::Long;
use Data::Array2ArrayMap::Hash::XSTree;

#my $help=0;
#my $limit=1;
#my $result = GetOptions (
#    "help"  => \$help,
#    "limit=i"  => \$limit,
#);
#if ($help) {
#    pod2usage();
#}

my $CONFLICT=Data::Array2ArrayMap::Hash::XSTree->new();

while (<>) {
    next if /^\s*$/;
    my ($pkg1,$pkg2,$file1)=split(/\t/,$_);
    $CONFLICT->append([$pkg1,$pkg2],[$file1]);
}

foreach my $pkg1 (sort $CONFLICT->keys_at([])) {
    foreach my $pkg2 (sort $CONFLICT->keys_at([$pkg1])) {
	my @conflicts=$CONFLICT->get([$pkg1,$pkg2]);
	#print "CONFL for $pkg1,$pkg2 = @conflicts\n";
	my $msg;
	if (@conflicts==1) {
	    $msg="File $conflicts[0] conflicts with the package $pkg2.";
	} elsif (@conflicts<4) {
	    $msg='Files '.join(' ',@conflicts)." conflict with the package $pkg2.";
	} else {
	    $msg="There are file conflicts with the package $pkg2, for example, $conflicts[0] (".scalar @conflicts." file conflicts in total).";
	}
	$msg.=' Moreover, the packages have no explicit conflicts with each other. You should add explicit conflicts, or, if conflicts are avoidable, consider using alternatives.';
	print "$pkg1\t$msg\n";
    }
}


=head1	NAME

repocop-unittest-rpm-filesystem-message-helper - print formatted messages for file confilct tests

