<?php

namespace App\Models;

use CodeIgniter\Model;

class PagoModel extends Model
{
    protected $table            = 'pago';
    protected $primaryKey       = 'id_pago';
    protected $useAutoIncrement = true;
    protected $returnType       = 'App\Entities\Pago';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = [
        'id_reserva',
        'monto',
        'metodo',
        'estado',
        'referencia'
    ];

    protected $validationRules = [
        'id_reserva' => 'required|integer',
        'monto'      => 'required|numeric|greater_than[0]',
        'metodo'     => 'required|in_list[efectivo,tarjeta,yape,plin,transferencia]',
        'estado'     => 'required|in_list[pendiente,aprobado,rechazado,reembolsado]',
        'referencia' => 'permit_empty|max_length[100]',
    ];

    public function getPagosConReserva()
    {
        return $this->select('pago.*, usuario.nombres as cliente_nombres, usuario.apellidos as cliente_apellidos, reserva.total as reserva_total')
                    ->join('reserva', 'reserva.id_reserva = pago.id_reserva')
                    ->join('usuario', 'usuario.id_usuario = reserva.id_usuario')
                    ->findAll();
    }
}
