#------------------------------------------------------------
# Copyright (C) 2010 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package Common::CountryList;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Country;

use Common::FormObject;
use base 'Common::FormObject';

use Carp;

sub _init {
    my ( $self, %args ) = @_;

    $self->SUPER::_init(%args);

    $self->{Country} = [];

    # an href of country codes: {'US' => 1}
    #
    my $omit = $args{omit} || {};
    my $include = $args{include};

    my $collection = Common::DB::Item::Country->GetAll();

    while ( my $countryDBItem = $collection->next() ) {
        my $countryCode = $countryDBItem->alpha2();

        next if ( $omit->{$countryCode} || ( $include && !$include->{$countryCode} ) );

        push @{ $self->{Country} }, new Common::Country( dbItem => $countryDBItem );
    }

    return $self;
}

1;
