<?php

namespace App\Console;

use App\Console\Commands\EliminarRecibosTrash;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\EliminarRecibosTrash::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command(EliminarRecibosTrash::class)->daily();
        // $schedule->command('inspire')
        //          ->hourly();
        $schedule->call(function () {
            $db = DB::table('tramite_usuario')->where('tramite_procedimiento_id_tramite_tipo', '=', '1')
                ->where('updated_at', '<', 'date_sub(now(), interval 10 day)');

            foreach ($db->get() as $tramite_usuario)
            {
                DB::table('tramite_usuario_documento')->where('id_tramite_usuario', '=', $tramite_usuario->id)->delete();
                DB::table('tramite_usuario_observacion')->where('id_tramite_usuario', '=', $tramite_usuario->id)->delete();
                DB::table('tramite_usuario_requisito')->where('id_tramite_usuario', '=', $tramite_usuario->id)->delete();
            }

            $db->delete();
        })->daily();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}
