# Link between Chariots
# =====================
#
# A potential link between two chariot stops. Might actually not exist. Comes
# into existence when a defined value of needed repairs is assigned. Can tell
# if it is open (0 repairs needed) and what the reciprocal link is.

package ATITD::Chariot::Link;

use strict;
use warnings;

# Create a new potential link going from one stop to another. Optionally brings
# it into existence with a number of repairs needed.
sub new {
	my ($class, $from, $to, $needed) = @_;
	my $self = bless {
		from => $from,
		to => $to,
		needed => $needed,
	}, $class;
	
	return $self;
}

# Chariot stop this link starts.
sub from { $_[0]->{from} }

# Chariot stop this link ends.
sub to { $_[0]->{to} }

# Number of repairs needed for this link to open, or undef if this link doesn't
# really exist.
sub needed { $_[0]->{needed} }

# Sets the number of repairs needed.
sub set_needed { $_[0]->{needed} = $_[1] }

# Is this link open?
sub open { $_[0]->exists && $_[0]->needed == 0 }

# Does this link exist?
sub exists { defined $_[0]->needed }

# Reciprocal link (the link with the from and to stops swapped).
sub reciprocal { $_[0]->to->link($_[0]->from) }

1;
