package Vee::Schema::LocationEncounters;

use strict;
use warnings;
use base 'DBIx::Class';

=head1 NAME

Vee::Schema::LocationEncounters - DBIC class for the C<location_encounters> table

=cut

__PACKAGE__->load_components('Core');
__PACKAGE__->table('location_encounters');
__PACKAGE__->add_columns(qw/ location_id rarity version section pokemon_id method min_level max_level /);
__PACKAGE__->set_primary_key(qw/ location_id rarity /);

__PACKAGE__->belongs_to(pokemon => 'Vee::Schema::Pokemon', 'pokemon_id');
__PACKAGE__->belongs_to(location => 'Vee::Schema::Locations', 'location_id');

=head1 METHODS

=head2 level

Returns this encounter's level range formatted in a human-readable way, i.e.
"A - B", or just "A" if the range is actually just one level.

=cut

sub level {
    my ($self) = @_;
    
    my $level;
    my ($min, $max) = ($self->min_level, $self->max_level);

    if ($min == $max) {
        $level = $min;
    } else {
        $level = $min . ' - ' . $max;
    }

    return $level;
}

=head1 SEE ALSO

L<Vee::Schema>, L<DBIx::Class>

=head1 AUTHOR

Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>)

See the included F<AUTHORS> file for a full list of contributers.

=head1 LICENSE

See the included F<LICENSE> file.

=cut

1;
