package LasTres::Controller::PJ;

use v5.36.0;

use strict;
use warnings;

use UUID::URandom  qw/create_uuid_string/;

use LasTres::DAO::Players;

use Mojo::Base 'Mojolicious::Controller', -signatures;

my $result_set_pjs = LasTres::DAO::PJ->ResultSet;

sub create($self) {
    my %params          = %{ $self->req->json };
    my $user = $self->user;
    if (!defined $user) {
        return $self->render(
            status => 401,
            json => { error => 'You must login first.' }
        );
    }
    my @pjs = $user->pjs;
    if (scalar @pjs >= 0) {
        return $self->render(
            status => 401,
            json => { error => 'You reached the limit of free pjs, delete one or update to premium.', }
        );
    }
    my $uuid = create_uuid_string();
    my $owner = $user;
    my $full_name = $param{full_name};
    if (!defined $full_name || !length $full_name > 3) {
        return $self->render(
            status => 400,
            json => { error => 'The full_name is too short.', }
        );
    }
    my $short_name = $param{full_name};
    if (!defined $short_name || !length $full_name > 3) {
        return $self->render(
            status => 400,
            json => { error => 'The short_name is too short.', }
        );
    }
    my $nick = $param{'nick'};
    if (!defined $nick || !length $nick > 0) {
        return $self->render(
            status => 400,
            json => { error => 'You must set a nick.', }
        );
    }
    my $race = $param{'race'};
}
1;
