package ProjectBuilder::Model::Confs;
use Mojo::Base -base;
use ProjectBuilder::Conf;
use Data::Dumper;

sub add {
  my ($self, $conf) = @_;
  my $sql = 'insert into confs (title, body) values (?, ?) returning id';
  #return $self->pg->db->query($sql, $conf->{title}, $conf->{body})->hash->{id};
}

sub all { #shift->pg->db->query('select * from confs')->hashes->to_array 
	my @confs;
	my $i = 0;
	foreach my $k (pb_conf_get_all()) {
		my ($v) = pb_conf_get($k);
		$confs[$i] = {	id => $k,
				body => $v->{"pb"},
		};
		$i++;
	}
	#print "PARAMS: ".Dumper(@confs)."\n";
	return(\@confs);
}

sub find {
  my ($self, $id) = @_;
  #return $self->pg->db->query('select * from confs where id = ?', $id)->hash;
}

sub remove { #shift->pg->db->query('delete from confs where id = ?', shift) 
}

sub save {
  my ($self, $id, $conf) = @_;
  my $sql = 'update confs set title = ?, body = ? where id = ?';
  #$self->pg->db->query($sql, $conf->{title}, $conf->{body}, $id);
}

1;
