<?php

namespace App\Jobs;

use App\Models\CompanyDetails;
use App\Models\CompanyDetailsSetup;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    private $request;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($request)
    {
        $this->request = $request;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Request $request)
    {
        $company_details = CompanyDetails::find(1);
        $company_setup = CompanyDetailsSetup::find(1);

        $company_details->type = $this->request['status'];
        $company_details->save();

        /*Company Setups*/
        $company_setup->system_version = $this->request['system-version'];
        $company_setup->version_from = $this->request['version-from'];
        $company_setup->branches = $this->request['branches'];
        $company_setup->time_out = $this->request['time-out'];
        $company_setup->liv_sp = $this->request['live-support'];
        $company_setup->w_tax = $this->request['w-tax'];
        $company_setup->pay_premium = $this->request['pay-premium'];
        $company_setup->motor_valuations = $this->request['motor-valuation'];
        $company_setup->two_way_verif = $this->request['two-step-verification'];
        $company_setup->dont_debit_renewals = $this->request['no-debiting-renewals'];
        $company_setup->max_cert_ext = $this->request['max-cert-extension'];
        $company_setup->receipting_mode = $this->request['receipting'];
        $company_setup->markup = $this->request['markup'];
        $company_setup->round_off = $this->request['round-off'];
        $company_setup->contact_on_rn = $this->request['contacts-on-rn'];
        $company_setup->rate_on_rn = $this->request['rate-on-rn'];
        $company_setup->require_client_docs = $this->request['kyc-docs'];
        $company_setup->require_risk_manager = $this->request['risk-managers'];
        $company_setup->require_account_handler = $this->request['account-handlers'];
        $company_setup->allow_uploads = $this->request['uploads'];
        $company_setup->allow_exports = $this->request['exports'];
        $company_setup->save();
    }

}
