<?php

namespace App\Models;

use CodeIgniter\Model;

class ReservaModel extends Model
{
    protected $table            = 'reserva';
    protected $primaryKey       = 'id_reserva';
    protected $useAutoIncrement = true;
    protected $returnType       = 'App\Entities\Reserva';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = [
        'id_usuario',
        'total',
        'estado'
    ];

    protected $validationRules = [
        'id_usuario' => 'required|integer',
        'total'      => 'required|numeric|greater_than_equal_to[0]',
        'estado'     => 'required|in_list[pendiente,confirmada,cancelada,pagada]',
    ];

    public function getReservasConUsuario()
    {
        return $this->select('reserva.*, usuario.nombres, usuario.apellidos')
                    ->join('usuario', 'usuario.id_usuario = reserva.id_usuario')
                    ->findAll();
    }
}
