package OpenEmbeded::Image;

use Settings::Simple;
use Logging::LoggerManager;

sub new {
    my $class=shift;
    my $source=shift;
    my $self = bless { source=> $source}, $class;
    my $settings = new Settings::Simple($source);
    
    if (!defined $settings || $settings->inject($self)!=0) {
        exit(1);
    }    
    return $self;
}

sub name {
    my $self = shift;
    if (@_) { $self->{name} = shift }
    return $self->{name};
}
sub logger {
    my $self = shift;
    if ( !defined $self->{logger} ) {
        $self->{logger} = Logging::LoggerManager::Instance->logger(__PACKAGE__);
    }
    return $self->{logger};
}

sub distribution {
    my $self = shift;
    if (@_) { $self->{distribution} = shift }
    return $self->{distribution};
}

sub branch {
    my $self = shift;
    if (@_) { $self->{branch} = shift }
    return $self->{branch};
}

sub packages {
    my $self = shift;
    if (@_) { @{ $self->{packages} } = @_; }
    return @{ $self->{packages} };
}

sub validate{
    my ( $self, $builder ) = @_;

     if (!defined $self->{packages}) {
        $self->logger->severe ("Missing package list in %s.", $self->{source});
        exit(1);        
    }
    if (!defined $self->{branch}) {
        $self->logger->severe ("Missing branch in %s.",  $self->{source});
        exit(1);        
    }    
    if (!defined $self->{distribution}) {
        $self->logger->severe ("Missing distribution in %s.",  $self->{source});
        exit(1);        
    }    
    $self->logger->section("Current Image");
    $self->logger->info( "   name                    : %s", $self->name );
    $self->logger->info( "   packages                : \n       %s", join("\n       ",$self->packages ));
}
1;
