<?php

namespace AuthStack\Driver\AUDGeneric\App\Services;

use Mail;
use AuthStack\Driver\AUDGeneric\App\Mail\PasswordTokenSent;

class Email
{
    /**
     * @param array $attributes
     * @param string $token
     * @return bool
     */
    public static function sendResetEmail(array $attributes, string $token)
    {
        $link = env('APP_URL') . '/aud/password/reset/' . $token . '?email=' . urlencode($attributes['email']);

        try {
            Mail::to($attributes['email'])->send(new PasswordTokenSent($attributes, $link));

            return true;

        } catch (\Exception $e) {

            \Log::error('Email Failure:', [
                'message' => $e->getMessage(),
                'file' => $e->getFile(),
                'line' => $e->getLine()
            ]);

            return false;
        }
    }
}