#
# HotdogVendor.pm: Provide a Hotdog Vendor
#
package HotdogVendor;

use strict;
use warnings;

sub new {
  my ($class, $name, $how_many) = @_;
  my $attrs = {
	       franks => $how_many,
	       buns => $how_many,
	       mustard => $how_many,
	       kraut => $how_many,
	       name => $name
	      };
  bless ($attrs, $class);
}

sub _use_product {
  my ($self, $product, $how_many) = @_;

  if (($self->{$product} - $how_many) < 1) {
    die "[$self->{name}] use_$product: Unable to processor order, not enough $product (you wanted $how_many, I only got $self->{$product}";
  }

  $self->{$product} -= $how_many;
}

sub _has_product {
  my ($self, $product) = @_;

  if (!defined $self->{$product}) {
    die "[$self->{name}] has_$product: undefined product (wrong vendor?!)";
  }

  return ($self->{$product});
}

# Franks
sub use_franks {
  my ($self, $how_many) = @_;

  $self->_use_product('franks', $how_many);
}
sub has_franks {
  my ($self) = shift;

  return ($self->_has_product('franks'));
}

# Buns
sub use_buns {
  my ($self, $how_many) = @_;

  $self->_use_product('buns', $how_many);
}
sub has_buns {
  my ($self) = shift;

  return ($self->_has_product('buns'));
}

# Mustard
sub use_mustard {
  my ($self, $how_many) = @_;

  $self->_use_product('mustard', $how_many);
}
sub has_mustard {
  my ($self) = shift;

  return ($self->_has_product('mustard'));
}

# Kraut
sub use_kraut {
  my ($self, $how_many) = @_;

  $self->_use_product('kraut', $how_many);
}
sub has_kraut {
  my ($self) = shift;

  return ($self->_has_product('kraut'));
}

# Name
sub name {
  my ($self) = shift;

  return ($self->{name});
}

1;
