<?php

namespace Daite\Coopdigital\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

// * Base de datos
use Illuminate\Support\Facades\DB;

class ControladorRegistro extends Controller {

    public function registroSesion(Request $request) {

        return view('coopdigital::registro');

    }

    public function verificarRegistro(Request $request) {

        $cedula = $request -> cedula;
        $codigo = $request -> codigo;

        $consulta =
        strcmp($cedula, 'USUARIO') == 0
        ?
        "
        EXEC [appmovil].[p_validar_valores_pantalla]
        '{$codigo}',
        'NUEVO_USUARIO'
        "
        :
        "
        EXEC [appmovil].[p_validar_valores_pantalla]
        '{$codigo}',
        'VALIDAR_REGISTRO',
        '',
        '',
        '{$cedula}';
        ";

        $datosRegistro = collect(DB::select($consulta)) -> first();

        return $datosRegistro;

    }

    public function registrarSesion(Request $request) {

        $codigo = $request -> codigo;
        $cedula = $request -> cedula;
        $usuario = $request -> usuario;
        $correo = $request -> correo;
        $contrasena = $request -> contrasena;

        $consulta =
        "EXEC [appmovil].[p_registrar_usuario] 
        {$codigo}', 
        {$cedula}', 
        {$usuario}', 
        {$correo}', 
        '{$contrasena}', 
        'web';";

        DB::unprepared($consulta);

        return view('coopdigital::autenticacion.inicio');

    }

}
