#!/usr/bin/perl

use strict;
use warnings;

use DateTime;
use Socket;
use JSON;
use Data::Dumper;


our $socket_path = '/var/run/vector/vector_rt.sock';
our @queue_list = qw(General);
our $id = 0;


sub send_dummy_transactions {
    my $queue = shift;
    my $dt = DateTime->now()->rfc3339();
    my %transaction = (
        id => $id,
        Type => 'Munge', # will be replaced by special reserved enum value
        Created => $dt,
        Interface => 'Scheduled job',
        TimeTaken => '0',
        Queue => $queue,
        Creator => {
            id => 'maintenance',
            type => 'bot',
            _url => 'nada'
    },
            Object => {
                id => 'nada',
                type => 'nada',
                _url => 'nada'
        }
    );
    require IO::Socket::UNIX;
    my $socket = IO::Socket::UNIX->new(
        Peer => $socket_path,
        Type => SOCK_STREAM()
    );
    die "Could not create socket: $!n" unless $socket;
    my $jsonized = JSON::to_json(\%transaction);
    print $socket $jsonized;
}

for my $queue (@queue_list) {
    send_dummy_transactions($queue);
}
