<?php

namespace App\Console\Commands;

use App\Models\User;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Models\Voucher;
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;
use Illuminate\Support\Facades\Log;

class OneTimeTestVoucherifyEmailCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */

    protected $signature = 'one-time-test-voucherify-email';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'One time test sending voucherify email to see out of alignment issue';

    /** @var FetchesVoucher */
    private $fetchesVoucher;

    /** @var GeneratesEmailVerificationAttempt */
    private $generatesEmailVerificationAttempt;

    /** @var SendUserVerificationEmail */
    private $sendUserVerificationEmail;

    /** @var GeneratesPasswordReset */
    private $generatesPasswordReset;

    /** @var SendResetPasswordEmail */
    private $sendResetPasswordEmail;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct(FetchesVoucher $fetchesVoucher, GeneratesEmailVerificationAttempt $generatesEmailVerificationAttempt, SendUserVerificationEmail $sendUserVerificationEmail, GeneratesPasswordReset $generatesPasswordReset, SendResetPasswordEmail $sendResetPasswordEmail)
    {
        parent::__construct();
        $this->fetchesVoucher = $fetchesVoucher;
        $this->generatesEmailVerificationAttempt = $generatesEmailVerificationAttempt;
        $this->sendUserVerificationEmail = $sendUserVerificationEmail;
        $this->generatesPasswordReset = $generatesPasswordReset;
        $this->sendResetPasswordEmail = $sendResetPasswordEmail;
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try{ //In case voucher got deleted unintentionally
            $user = User::where('id', 3974)->first(); //5436, 3974

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

            // $attempt = $this->generatesEmailVerificationAttempt->execute($user);
            // $this->sendUserVerificationEmail::dispatch($user, $attempt);

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

    }

}
