<?php

namespace App\Packages\Phone\Service;

use Aws\Sns\SnsClient;

/**
 * Class AmazonSmsService
 * @package App\Packages\User\Transformer
 */
class AmazonSmsService
{
    /** @var SnsClient */
    private $client;

    public function __construct()
    {
        $this->client = new SnsClient([
            'credentials' => [
                'key' => env('AWS_ACCESS_KEY_ID'),
                'secret' => env('AWS_SECRET_ACCESS_KEY'),
            ],
            'region' => 'us-east-1',
            'version' => 'latest',
        ]);

        $this->client->setSMSAttributes([
            'attributes' => ['DefaultSenderID' => 'TimeCaps'],
        ]);
    }

    /**
     * @param $verificationCode
     * @param $phoneCode
     * @param $phoneNumber
     *
     * @return \Aws\Result
     */
    public function sendVerificationNumber($verificationCode, $phoneCode, $phoneNumber)
    {
        $phoneCode = '+' . $phoneCode . $phoneNumber;
        $text = trans('main.sms_verification_code', [
            'code' => $verificationCode,
        ]);

        $args = [
            "SMSType" => "Transactional",
            "Message" => $text,
            "PhoneNumber" => $phoneCode,
        ];

        return $this->client->publish($args);
    }
}