<?php
/**
 * Email Settings Controller V1
 *
 * @package Licenzo\Http\Controller\Api\V1
 */

namespace Licenzo\Http\Controller\Api\V1;

use Licenzo\Framework\Http\Request;
use Licenzo\Helper\Settings;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Email Settings API Controller
 */
class EmailSettingsController
{
    /**
     * Get email settings
     *
     * @return array
     */
    public function get()
    {
        return [
            'success' => true,
            'settings' => Settings::getEmailSettings()
        ];
    }

    /**
     * Update email settings
     *
     * @param Request $request
     * @return array
     */
    public function update(Request $request)
    {
        $data = $request->getSafe([
            'from_name'     => 'sanitize_text_field',
            'from_email'    => 'sanitize_email',
            'reply_to'      => 'sanitize_email',
            'reply_to_name' => 'sanitize_text_field',
        ]);

        Settings::updateEmailSettings($data);

        return [
            'success' => true,
            'message' => 'Email settings updated successfully',
            'data' => Settings::getEmailSettings()
        ];
    }
}
