#------------------------------------------------------------
# Copyright (C) 2011 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Common::Postal;

use strict;
use warnings;

use lib '/app/tools/common/lib/';
use Common::Postal::US;
use Common::Postal::CA;

my %gPackageMap = (
    'US' => 'Common::Postal::US',    # United States
                                     # and its territories
    'AS' => 'Common::Postal::US',    # American Samoa
    'FM' => 'Common::Postal::US',    # Federated States of Micronesia
    'GU' => 'Common::Postal::US',    # Guam
    'MH' => 'Common::Postal::US',    # Marshall Islands
    'MP' => 'Common::Postal::US',    # Northern Mariana Islands
    'PR' => 'Common::Postal::US',    # Puerto Rico
    'PW' => 'Common::Postal::US',    # Palau
    'VI' => 'Common::Postal::US',    # Virgin Islands, U.S.

    # UM - United States Minor Outlying Islands is the notable
    # exception as there are no postal codes assigned (or
    # USPS state abbreviation), so even though it would seem...

    'CA' => 'Common::Postal::CA',    # Canada
);

sub new {
    my ( $class, $country ) = @_;

    my $pkg = $gPackageMap{$country};

    if ($pkg) {
        my $self = $pkg->new();
        $self->{country} = $country;
        return $self;
    }

    return undef;
}

sub country {
    my ($self) = @_;

    # we don't know anything else, so all we can do
    # is return the country we were instantiated with

    return $self->{country};
}

# pure virtual methods

sub getName          { die 'must be overloaded' }
sub getAbbr          { die 'must be overloaded' }
sub formatPostalCode { die 'must be overloaded' }

1;
