# Initial data for a fresh AT Installation.
use RTx::AssetTracker;
use RTx::AssetTracker::Type;

@Types = ({ Name               => 'Servers',
             Description       => 'The default asset type',
          });

@Final = ( \&AssetTypes, \&AssetScripConditions, \&AssetScripActions, \&AssetTemplates, );

my $CurrentUser = RT::CurrentUser->new();
$CurrentUser->LoadByName('RT_System');

sub AssetTypes {
    print "Creating default asset types...";

    for $item (@Types) {
        my $new_entry = new RTx::AssetTracker::Type($CurrentUser);
        my ( $return, $msg ) = $new_entry->Create(%$item);
        print "(Error: $msg)" unless ($return);
        print $return. ".";
    }
    print "done.\n";
}

sub AssetScripConditions {
    print "Creating default asset scrips conditions...";

	my @Conditions = (
	    { Name => 'User Defined',
		  Description => 'Whenever a user-defined condition occurs',
		  ExecModule => 'UserDefined',
		  Argument => undef,
		  ApplicableTransTypes => 'Any' },
	);

    for $item (@Conditions) {
        my $new_entry = new RTx::AssetTracker::ScripCondition($CurrentUser);
        my ( $return, $msg ) = $new_entry->Create(%$item);
        print "(Error: $msg)" unless ($return);
        print $return. ".";
    }
    print "done.\n";
}

sub AssetScripActions {
    print "Creating default asset scrips actions...";

	my @Conditions = (
	    { Name => 'User Defined',
		  Description => 'Perform a user-defined action',
		  ExecModule => 'UserDefined',
		  Argument => undef },
	);

    for $item (@Conditions) {
        my $new_entry = new RTx::AssetTracker::ScripAction($CurrentUser);
        my ( $return, $msg ) = $new_entry->Create(%$item);
        print "(Error: $msg)" unless ($return);
        print $return. ".";
    }
    print "done.\n";
}

sub AssetTemplates {
    print "Creating default asset templates...";

	my @Conditions = (
	    { AssetType => 0,
		  Name => 'Blank',
		  Description => 'A blank template',
		  Content => undef },
	);

    for $item (@Conditions) {
        my $new_entry = new RTx::AssetTracker::Template($CurrentUser);
        my ( $return, $msg ) = $new_entry->Create(%$item);
        print "(Error: $msg)" unless ($return);
        print $return. ".";
    }
    print "done.\n";
}
