<?php
//DEPRICATED
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Deal\Deal;
use App\Models\Deal\DealStatus;

use Illuminate\Support\Facades\Log;


class ConfirmClientFromBitrix extends Controller
    {
    public function confirm(Request $request)
        {
        $deal = Deal::where('confirm_token', $request->hash)->first();
        if ((bool) $request->is_unique)
            {
            $deal->status = DealStatus::UNIQUE;
            }
        else
            {
            $deal->status = DealStatus::NOT_UNIQUE;
            }

        Log::build([
            'driver' => 'single',
            'path' => storage_path('logs/bitrix.log'),
        ])->error(
                json_encode(
                    [
                        'is_unique' => $request->is_unique,
                        'deal' => $deal->id,
                        'status' => $deal->status
                    ]
                )
            );
        $deal->save();
        return $deal->id;
        }
    }
