package BeastBB::Model::Group; use 5.32.1; use strict; use warnings; use Params::ValidationCompiler 'validation_for'; use Types::Standard qw/Int Str HashRef Bool/; use BeastBB::Response; { my $validator = validation_for( params => { id_group => { type => Int, optional => 1 }, groupname => { type => Str }, privileges => { type => HashRef [Bool], optional => 1 }, } ); sub new { my $class = shift; my %params = $validator->(@_); return bless \%params, $class; } } sub Hash { my $self = shift; my $maybe_id_group = $self->IdGroup; my $maybe_privileges = $self->Privileges; return { ( ( !$maybe_id_group->IsError ) ? ( id_group => $maybe_id_group->Content ) : () ), ( ( !$maybe_privileges->IsError ) ? ( privileges => $maybe_privileges->Content ) : () ), groupname => $self->{groupname}, }; } sub IdGroup { my $self = shift; my $id_group = $self->{id_group}; return BeastBB::Response->new( is_error => 1, error_message => 'No id group set to this model.' ) if !defined $id_group; return BeastBB::Response->new( content => $id_group ); } { my $validator = validation_for( params => [ { type => Int }, ] ); sub SetIdGroup { my $self = shift; my %params = $validator->(@_); my $id_group = shift; $self->{id_group} = $id_group; } } sub Groupname { my $self = shift; return $self->{groupname}; } { my $validator = validation_for( params => [ { type => HashRef [Bool], optional => 1 }, ], ); sub Privileges { my $self = shift; @_ = $validator->(@_); if (@_) { $self->{privileges} = shift; } if ( !defined $self->{privileges} ) { return BeastBB::Response->new( is_error => 1, error_message => 'Privileges not recovered yet for this group.' ); } return BeastBB::Response->new( content => $self->{privileges} ); } } 1;