package myHive::Controller::API::Sites;
use Moose;
use Data::Dumper;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

=head1 NAME

myHive::Controller::API::Sites - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut

sub begin : Private {
        my ( $self, $c ) = @_;

        $c->{authentication}    = myHive::Model::Authentication->new;
        $c->{manager}           = myHive::Model::Site::Manager->new;

        return;
}


=head2 index

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    $c->response->body('Matched myHive::Controller::API::Sites in API::Sites.');
}

sub add :Local : Args() {
	my ($self, $c, $seed ) = @_;
	if ($seed eq $c->session->{seed} ) {

                my %params;
                my $data = $c->request->body_parameters;
                $params{account}            	= $c->session->{account_id};
		$params{siteid}			= $data->{siteId};
                $params{area}                 	= $data->{areaId};
                $params{site_name}          	= $data->{siteName};
		$params{status}		    	= $data->{status};
		$params{landowner}		= 0;
		$params{broodtypes}             = '{}';
                print STDERR Dumper(\%params);
                $c->{manager}                   =  myHive::Model::Site::Manager->new(  account => $c->session->{account_id} );
                my ($status, $content  )        =  $c->{manager}->add( %params );
                if ( $status) {
                        $c->stash->{updated} = 'Y';
                        $c->stash->{status} = $content;
                }
                else {
                        $c->stash->{updated} = 'N';
                }
        }               
        $c->stash->{template} = 'rest/addsites.tt';
        return;

}


=head1 AUTHOR

root

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

1;
