package FixMyStreet::Geocode::Address::OSM;

use parent 'FixMyStreet::Geocode::Address';

sub brand { "OpenStreetMap" }

sub label { _("Nearest road to the pin placed on the map (automatically generated by %s): %s") }

sub summary {
    return $_[0]->{display_name};
}

sub parts {
    my $address = $_[0]->{address};
    return {
        number => $address->{house_number} || '',
        street => $address->{road} || '',
        postcode => $address->{postcode} || '',
    };
}

sub for_around {
    my $self = shift;
    return {
        road => $self->{address}{road},
        full_address => $self->{display_name},
    };
}

sub for_alert {
    my $self = shift;

    my $str = '';

    my $address = $self->{address};
    my @address;
    push @address, $address->{house_number} if $address->{house_number};
    push @address, $address->{road} if $address->{road};
    push @address, $address->{suburb} if $address->{suburb};
    push @address, $address->{town} if $address->{town};
    push @address, $address->{city} if $address->{city};
    $str .= sprintf($self->label, $self->brand, join( ', ', @address ) ) if @address;

    return $str;
}

1;
