<?php

namespace App\Http\Controllers\Ajax;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ArtistRematchingController extends Controller
{

    public function startRematching(Request $request) {

        $this->restCallMatchAllArtists($request);
    }

    /**
     *
     */
    private function restCallMatchAndPrepareOneTartistForAllTauctionObjects(Request $request) {

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => env('SERVICE_URL_MATCHANDPREPAREONETARTISTFORALLTAUCTIONOBJECTS').'?tArtistId='.$request->artist_id,
            CURLOPT_USERPWD => env('SERVICE_USERPASSWORD'),
            CURLOPT_ENCODING => "",
            //CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 10000,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => "",//$jsonData,
            CURLOPT_HTTPHEADER => array(
                "accept: */*",
                "accept-language: en-US,en;q=0.8",
                "content-type: application/json",
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);
        $info = curl_getinfo($curl);
        $httpStatusCode = $info['http_code'];

        curl_close($curl);

        if ($err) {
            echo "cURL Error #:" . $err;
        }

    }

    /**
     *
     */
    private function restCallMatchAllArtists(Request $request) {

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => env('SERVICE_URL_MATCHALLARTISTS'),
            CURLOPT_USERPWD => env('SERVICE_USERPASSWORD'),
            CURLOPT_ENCODING => "",
            //CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 10000,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => "",//$jsonData,
            CURLOPT_HTTPHEADER => array(
                "accept: */*",
                "accept-language: en-US,en;q=0.8",
                "content-type: application/json",
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);
        $info = curl_getinfo($curl);
        $httpStatusCode = $info['http_code'];

        curl_close($curl);

        //$response = json_decode($response);

        if ($err) {
            echo "cURL Error #:" . $err;
        }

    }
}
