<?php
namespace App\Bundle\Sms;

use App\Bundle\Utils\Logger;

class Manager
{
	private $client = null;

    public function __construct($client)
    {
    	$this->client = $client;    
    }

    public function sendSmsSova(string $to, string $msg)
    {
        $response = $this->client->request('GET', '/sms/send', [
            'verify_peer' => false,
            'verify_host' => false,
            'base_uri' => 'https://sms.ru',
            'headers' => [
                'Content-Type' => 'application/json',
                'User-Agent' => 'sovamed_bot'
            ],
            'query' => [ 
                'to' => $to,
                'msg' => $msg,
                'from' => $_ENV['SMSRU_FROM_SOVAMED'],
                'json' => 1,
                'api_id' => $_ENV['SMSRU_KEY_API'],
                'test' => 0
            ],
        ]);
        
        $response = $response->toArray();

        Logger::send($response, 'sms.log');
        
        return $response;
    }

    public function sendSmsWmt(string $to, string $msg)
    {
        $response = $this->client->request('POST', '/v1/sms', [
            'verify_peer' => false,
            'verify_host' => false,
            'base_uri' => 'https://api.sms4b.ru',
            'headers' => [
                'Authorization' => $_ENV['SMS4B_TOKEN'],
                'Content-Type' => 'application/json',
                'User-Agent' => 'wmtmed_bot'
            ],
            'body' => json_encode([ 
                'sender' => $_ENV['SMS4B_FROM_WMTMED'],
                'messages' => [ 
                    [
                        'number' => $to,
                        'text' => $msg
                    ]
                ]
            ]),
        ]);
        
        $response = $response->toArray();

        Logger::send($response, 'sms4b.log');

        return $response;
    }
}