<?php

namespace ModulesGarden\OpenXchangeAddon\Core\Configuration\Addon\Activate;

use ModulesGarden\OpenXchangeAddon\Core\Configuration\Addon\AbstractAfter;
use ModulesGarden\OpenXchangeAddon\Core\Models\Whmcs\EmailTemplate;

/**
 * Runs after module activation actions
 *
 * @author Rafał Ossowski <rafal.os@modulesgarden.com>
 */
class After extends AbstractAfter
{
    /**
     * @param array $params
     * @return array
     */
    public function execute(array $params = [])
    {
        $upgradeInfoTemplate = EmailTemplate::where('name', '=', 'OpenXchange Upgrade Product')->where('type', '=', 'product')->first();

        if (!$upgradeInfoTemplate || empty($upgradeInfoTemplate))
        {
            //there is not template. Create a new one
            EmailTemplate::insert([
                'type' => 'product',
                'name' => 'OpenXchange Upgrade Product',
                'subject' => 'OpenXchange Product Upgraded',
                'message' => '<p>
                            Dear {$client_name},
                            </p>
                            <p>
                            You upgraded the service: {$service_product_name}, but you will need to change the class of service of your mailboxes manually.
                            </p>',
                'custom' => 1
            ]);
        }

        return $params;
    }
}
