package LasTres::Stats;

use v5.36.0;

use strict;
use warnings;

use feature 'signatures';

use Moo;

use LasTres::DAO::Stats;

my $result_set = LasTres::DAO::Stats->new->ResultSet;

has uuid => (
    is       => 'rw',
    required => 0,
);

has health => (
    is       => 'rw',
    required => 1,
);

has mana => (
    is       => 'rw',
    required => 1,
);

has strength => (
    is       => 'rw',
    required => 1,
);

has resistance => (
    is       => 'rw',
    required => 1,
);

has magic => (
    is       => 'rw',
    required => 1,
);

has speed => (
    is       => 'rw',
    required => 1,
);

has intelligence => (
    is       => 'rw',
    required => 1,
);

sub hash ($self) {
    my $uuid = $self->uuid;
    return {
        ( ( defined $uuid ) ? ( uuid => $uuid ) : () ),
        health       => $self->health,
        mana         => $self->mana,
        strength     => $self->strength,
        resistance   => $self->resistance,
        magic        => $self->magic,
        speed        => $self->speed,
        intelligence => $self->intelligence
    };
}

sub update($self) {
    return $self->result_set->update; 
}

sub insert($self) {
    return $self->result_set->insert; 
}

sub update_or_insert($self) {
    return $self->result_set->update_or_insert; 
}

sub result_set ($self) {
    if (!defined $self->uuid) {
        die "This Stat has no correlation with db, unable to continue.";
    }
    $result_set->new( $self->hash );
}
1;
