<?php

namespace App\Classes\Modules\Accounts\Processors;

use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationToken;
use App\Classes\Modules\Accounts\Services\InvalidatesAuthenticationToken;
use App\Models\User;

class RefreshAuthenticationTokenProcessor
{

    /** @var InvalidatesAuthenticationToken */
    private $invalidatesAuthenticationToken;

    /** @var GeneratesAuthenticationToken */
    private $generatesAuthenticationToken;

    /**
     * RefreshAuthenticationTokenLogic constructor.
     * @param InvalidatesAuthenticationToken $invalidatesAuthenticationToken
     * @param GeneratesAuthenticationToken $generatesAuthenticationToken
     */
    public function __construct(InvalidatesAuthenticationToken $invalidatesAuthenticationToken, GeneratesAuthenticationToken $generatesAuthenticationToken)
    {
        $this->invalidatesAuthenticationToken = $invalidatesAuthenticationToken;
        $this->generatesAuthenticationToken = $generatesAuthenticationToken;
    }


    /**
     * @param User $user
     * @return array
     * @throws \App\Classes\Exceptions\InternalServerErrorException
     */
    public function execute(User $user): array {

        $this->invalidatesAuthenticationToken->execute();

        return ['refresh_token' => $this->generatesAuthenticationToken->execute($user)];

    }

}