<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Carbon\Carbon;
use App\Models\Billet;

use Mail;

class SendEmailsCommand extends Command
{


    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:send-emails-command';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {

        $billets = Billet::where('send', "true")->get();

        foreach ($billets as $billet) {


            $hoursDifferencedays = Carbon::now()->diffInHours($billet->date);
dd($hoursDifferencedays);

            $hoursDifferenceweeks = Carbon::now()->diffInHours($billet->date);

 
            if ($hoursDifferencedays === 60 || $hoursDifferencedays === 336) {
                $mailData = [
                    'title' => $billet->title,
                    'date' => $billet->date
                ];
              
                $this->sendEmail($billet->email,$mailData);
                $billet->send = "false";
                $billet->save();
            $this->info('Date.');

            }

        }

        $this->info('Emails sent successfully.');
    }
    private function sendEmail($clientEmail,$mailData)
    {

        Mail::to($clientEmail)->send(new \App\Mail\BilletReminderMail($mailData));
    }
}
