package Geo::USCensus::Geocoding::Match;

use strict;
use Data::Dumper;

sub new {
  my $class = shift;
  my $address = shift;
  my $census = shift;

  my $self = { %$address };
  bless $self, $class;
}

sub matchedAddress {
  my $self = shift;
  $self->{matchedAddress};
}

sub coordinates {
  my $self = shift;
  $self->{coordinates};
}

sub addressComponents {
  my $self = shift;
  $self->{addressComponents};
}

sub geographies {
  my $self = shift;
  $self->{geographies};
}

sub block_info {
  my $self = shift;
  my $geo = $self->{geographies};
  my $block_info = $geo->{'2010 Census Blocks'}; # XXX change this in 2020
  if ($block_info and exists($block_info->[0])) {
    return $block_info->[0];
  } else {
    warn "2010 Census Blocks element not found in response\n";
    warn Dumper $self->{geographies};
    return '';
  }
}

sub censustract {
  my $self = shift;
  my $block = $self->block_info or return '';
  return $block->{STATE} . $block->{COUNTY} . $block->{TRACT};
}

1;
