<?php

namespace App\Classes\Jobs\Commands\V2;

use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Models\User;
use App\Classes\ValueObjects\Constants\Vouchers;
use App\Classes\Jobs\SendWelcomeVoucherEmail;
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
use App\Classes\Jobs\SendUserVerificationEmail;
use App\Classes\Modules\Accounts\Services\GeneratesEmailVerificationAttempt;
use App\Classes\Jobs\SendResetPasswordEmail;
use App\Classes\Modules\Accounts\Services\GeneratesPasswordReset;


class OneTimeTestVoucherifyEmailV2CommandJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    public function handle()
    {
        Log::info(Carbon::now() . ': Start job - One time test sending voucherify email to see out of alignment issue.');
        $start   = new Carbon();

        try{ //In case voucher got deleted unintentionally
            $user = User::where('id', 3974)->first(); //5436, 3974

            Log::info(json_encode($user));
            $voucher = (App()->make(FetchesVoucher::class))->execute(['code' => Vouchers::WELCOME_50_PERCENT_OFF]);
            Log::info(json_encode($voucher));
            if($voucher) SendWelcomeVoucherEmail::dispatch($user, $voucher, 1);

            // $attempt = (App()->make(GeneratesEmailVerificationAttempt::class))->execute($user);
            // $this->sendUserVerificationEmail::dispatch($user, $attempt);

            // $attempt = (App()->make(GeneratesPasswordReset::class))->execute($user);
            // $this->sendResetPasswordEmail::dispatch($user, $attempt);
        }
        catch(\Exception $e){}


        $end = new Carbon();
        $elapsedTime = $start->diff($end)->format('%H:%I:%S');
        Log::info(Carbon::now() . ': End job - One time test sending voucherify email to see out of alignment issue. ElapsedTime: ' . $elapsedTime . '.');
    }
}
