<?php

namespace App\Http\Controllers;

use App\Enums\StatusEnum;
use App\Http\Requests\LicenseRequest;
use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;

class CoreController extends Controller
{
    public function domainNotVerified()
    {
        $title = translate('Domain Verification failed');

        return view('domain_not_verified', [
            'title' => $title,
        ]);

    }

    /**
     * checkLicense
     *
     * @param LicenseRequest $request
     * 
     * @return [type]
     */
    public function checkLicense(LicenseRequest $request)
    {
        $current_time = Carbon::now();

        Setting::updateOrInsert(
            ['key' => 'next_verification'],
            ['value' => $current_time->addYears(100)]
        );

        Setting::updateOrInsert(
            ['key' => 'is_domain_verified'],
            ['value' => StatusEnum::TRUE->status()]
        );

        Setting::updateOrInsert(
            ['key' => 'domain_verified_at'],
            ['value' => $current_time]
        );

        update_env('PURCHASE_KEY', 'NULLED-BY-ANTIGRAVITY');
        update_env('ENVATO_USERNAME', 'antigravity');

        optimize_clear();
        $notify[] = ["success", 'Domain is verified'];
        return redirect()->route('home')->withNotify($notify);
    }
}
