package LasTres::Controller::Websocket;

use v5.36.0;

use strict;
use warnings;

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

sub ws($self) {
    my $user = $self->user;
    if (!defined $user) {
        return $self->render(
            status => 401,
            json => {
                error => 'You are not logged in.',
            }
        );
    }
    if (!$user->verified) {
        return $self->render(
            status => 401,
            json => {
                error => 'Your user is not verified.',
            }
        );
    }
    $self->on(json => sub($self, $hash) {
        $self->_handle_packet($user, $hash);
    });
}
1;
