<?php

namespace App\Modules\Utilitarios\Controllers;
use App\Http\Controllers\Controller;
use App\Modules\Utilitarios\Models\Distrito;
use Illuminate\Http\Request;
use Yajra\Datatables\Datatables;
use Illuminate\Support\Facades\Validator;
use App\Services\SunatService;
use App\Services\CurlService;
use App\Mail\ComprasMail;
use DOMDocument;
use Mail; //Importante incluir la clase Mail, que será la encargada del envío

class UtilitariosController extends Controller
{
    protected $distritos;
    protected $to = 'pedrojosavila@gmail.com';
    function __construct(){
        $this->middleware('auth');
        $this->distritos = new Distrito();

    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   
        /*$data = [
            'link' => 'https://jesuschicano.es'
        ];
        Mail::to($this->to)->send(new ComprasMail($data));*/

    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {

    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
       if ($request->has('action')) {
            switch ($request->input("action")) {
                case 'search_ubigeo':
                    $validator = Validator::make($request->all(),[
                        'ubigeo' => 'required',
                    ]);
                    if ($validator->fails()) {
                       return response()->json(['error'=>$validator->errors()->all()]);
                    }else{
                        $this->distritos->id = $request->input('ubigeo');
                        $distritos = $this->distritos->search_ubigeo_id();
                        return response()->json(['distritos'=>$distritos]);
                    }
                break;
                case 'reload_divisa':
                    # code...
                break;
            }
        }else{
             return response()->json(['error'=>'No existe ningun token por favor no borre nuesto codigo html']);
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
       
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {

    }
}
