#package femaletwo;
package femaleshash;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(makehash addday isbleeding viewfemale problemswiththisone);
#use List::Util qw(any);
#use Math::Random qw(random_normal);
#use File::Slurp;

#my $Census = 0;
#my @rands = read_file('randoms3.txt');

#sub new {
sub makehash {
#    my $proto = shift;
#    my $class = ref($proto) || $proto;
    my ($type, $duration, $cyclelength, $start, $internalclock, $bleedingdaysref) = @_;
#    $type ||= 0;
    my $self = {};
#    $Census+=1;
    $self->{type} = $type;
    $self->{duration} = $duration;
    $self->{cyclelength} = $cyclelength;
    $self->{start} = $start;
    $self->{internalclock} = $internalclock;
    $self->{bleedingdays} = $bleedingdaysref;
##    $self->{duration}      = sample 1, (3, 4, 4, 4, 5, 5, 5, 6);
##	my @durations = (3, 4, 4, 4, 5, 5, 5, 6);
##    $self->{duration}      = $durations[getrandom($Census, \@rands)];
##	$self->{cyclelength}   = int(random_normal(1, 28.7, 2.5)+0.5);
##	$self->{cyclelength}   = getrandom($Census+1, \@rands); 
##    $self->{start}         = int(rand($self->{cyclelength}));
##    $self->{start}         = getrandom($Census+2, \@rands);
##    my @bleedingdays       = map {$_ % $self->{cyclelength}} $self->{start}..$self->{start} + $self->{duration}-1;
##    $self->{bleedingdays}  = $type ? \@bleedingdays : calcbleedingdays($self);
##    $self->{internalclock} = 0;
#    bless ($self, $class);
    return $self;
}

#sub population {
#    return $Census;
#}

sub addday {
	my $self = shift;
	$self->{internalclock}++;
#	$self->{internalclock} += 1;
#	$self->{internalclock} = $self->{internalclock} + 1;	
}
=itsahash
sub start {
    my $self = shift;
    if (@_) { $self->{start} = shift }
    return $self->{start};
}

sub duration {
    my $self = shift;
    if (@_) { $self->{duration} = shift }
    return $self->{duration};
}

sub cyclelength {
    my $self = shift;
    if (@_) { $self->{cyclelength} = shift }
    return $self->{cyclelength};
}

sub internalclock {
    my $self = shift;
    if (@_) { $self->{internalclock} = shift }
    return $self->{internalclock};
}

sub bleedingdays {
    my $self = shift;
    my @bleedingdays = @_;
    if (@_) { $self->{bleedingdays} = \@bleedingdays }
    return $self->{bleedingdays};
}

sub calcbleedingdays {
    my $self = shift;
    my @bleedingdays = map {$_ % $self->{cyclelength}} $self->{start}..$self->{start} + $self->{duration}-1;
	return \@bleedingdays;
}
=cut
sub isbleeding {
    my $self = shift;
#	my $res = any {$_ == $self->{internalclock} % $self->{cyclelength}} @{$self->{bleedingdays}};
	my $res = 0;

	for (@{$self->{bleedingdays}}) {
		if ($_ == $self->{internalclock} % $self->{cyclelength}) {
			$res = 1;
			last;
		}
	}
	
#	return $res ? 1 : 0;
	return $res;
}

sub mustbefedwithstick {
    my $self = shift;
    return isbleeding($self);
}

sub maynevertalktomales {
    my $self = shift;
    return isbleeding($self);
}

sub adversetransfer {
    my $self = shift;
    return isbleeding($self);
}

sub wherearetheyanyway {
    my $self = shift;
    return isbleeding($self);
}

sub problemswiththisone {
    my $self = shift;
    my $advice;
    if (isbleeding($self)) {
    	$advice = "create a different area to exist in for them\nseek local assistance from females\n";
    } elsif (takingdrugs($self)) {
        $advice = "protect eyes\nbecome over-sensitised to women\nooohhh become over-sensitised to women\n";
    } elsif (needsdoctor($self)) {
        $advice = "seek medical remedy\n";    
    } else {
        $advice = refreshthegood($self);
    }
    return $advice;
}

sub takingdrugs() {
	my $self = shift;
	return;
}

sub needsdoctor() {
	my $self = shift;
	return;
}

sub refreshthegood() {
	my $self = shift;
	return "seek assistance from females\nfind out from men what they know\n";
}

sub viewfemale {
	my $self = shift;
	print join "\n", map {$self->$_} qw(start duration cyclelength internalclock isbleeding);
	print "\n", join(' ', @{$self->bleedingdays}), "\n";
}

#sub getrandom {
#	my ($index, $rands) = @_;
#	my $r = $rands->[$index];
#	chomp $r;
#	return int $r;
#}

#sub DESTROY { 
#	--$Census;
##	--@rands;
#}

1;
