<?php


namespace App\ChameFacil;

class UsuarioServiceCF {

    public function createUsuarioCf($response_auth, $medico_registration_vm, $passwd) {

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => 'http://chamefacilpettree.prolins.com.br/api/usuario/Adicionar',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>'{
                "Codigo":0,
                "Nome":"'. $medico_registration_vm->getNome() . '",
                "Login":"'. $medico_registration_vm->getEmail() . '",
                "Senha":"'. $passwd . '",
                "CodigoPerfil":1,
                "Cadastro":"2022-09-08 00:00:00",
                "Ativo":1,
                "Email":"'. $medico_registration_vm->getEmail() . '",
                "TokenPushRequest":""
            }',
            CURLOPT_HTTPHEADER => array(
                'token:' . $response_auth->Token . '',
                'Content-Type: application/json'
            ),
        ));

        $response = curl_exec($curl);

        curl_close($curl);
        return json_decode($response);
    }


    public function updateUsuarioCf($medico_update_vm, $passwd, $response_id_cf) {

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => 'http://chamefacilpettree.prolins.com.br/api/usuario/Editar',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>'{
                "Codigo":'.$response_id_cf.',
                "Nome":"'. $medico_update_vm->getEmail() . '",
                "Login":"'. $medico_update_vm->getEmail() . '",
                "Senha":"'. $passwd . '",
                "CodigoPerfil":1,
                "Cadastro":"2022-09-08 00:00:00",
                "Ativo":1,
                "Email":"'. $medico_update_vm->getEmail() . '",
                "TokenPushRequest":""
            }',
            CURLOPT_HTTPHEADER => array(
                'token: baced76b-58bd-46f4-b009-d035c33e98e16ba31c06-045f-4b68-9319-0679b1d7eddf96fe103f-f418-445f-8ad9-39f48384fcdb2d8e2787-cbed-4bed-9c9c-5101fd3cf163117e2d82-0199-44c7-acd0-da3a7dfe524c',
                'Content-Type: application/json'
            ),
        ));

        $response = curl_exec($curl);

        curl_close($curl);
        return json_decode($response);
    }


}
