<?php
/**
 * Provider preset configuration.
 *
 * @package MailDoctor
 */

namespace MailDoctor\Mail\Config\Providers;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Defines preset SMTP credentials for popular providers.
 */
class Presets {

	/**
	 * Retrieve every provider preset.
	 *
	 * @return array<string, array<string, mixed>>
	 */
	public static function all(): array {
		return array(
			'sendgrid' => array(
				'label' => __( 'SendGrid', 'mail-doctor' ),
				'help'  => __( 'Uses smtp.sendgrid.net on port 587 with TLS and username "apikey".', 'mail-doctor' ),
				'data'  => array(
					'smtp_host'       => 'smtp.sendgrid.net',
					'smtp_port'       => 587,
					'smtp_encryption' => 'tls',
					'smtp_username'   => 'apikey',
				),
			),
			'mailgun'  => array(
				'label' => __( 'Mailgun', 'mail-doctor' ),
				'help'  => __( 'smtp.mailgun.org with TLS on port 587. Username is usually postmaster@yourdomain.', 'mail-doctor' ),
				'data'  => array(
					'smtp_host'       => 'smtp.mailgun.org',
					'smtp_port'       => 587,
					'smtp_encryption' => 'tls',
				),
			),
			'ses'      => array(
				'label' => __( 'Amazon SES', 'mail-doctor' ),
				'help'  => __( 'Use your region-specific SMTP endpoint (e.g. email-smtp.us-east-1.amazonaws.com) with TLS on port 587.', 'mail-doctor' ),
				'data'  => array(
					'smtp_port'       => 587,
					'smtp_encryption' => 'tls',
				),
			),
			'gmail'    => array(
				'label' => __( 'Gmail / Workspace', 'mail-doctor' ),
				'help'  => __( 'smtp.gmail.com with TLS on port 587. Requires an App Password.', 'mail-doctor' ),
				'data'  => array(
					'smtp_host'       => 'smtp.gmail.com',
					'smtp_port'       => 587,
					'smtp_encryption' => 'tls',
				),
			),
			'mailtrap' => array(
				'label' => __( 'Mailtrap Sandbox', 'mail-doctor' ),
				'help'  => __( 'sandbox.smtp.mailtrap.io on port 587 with TLS.', 'mail-doctor' ),
				'data'  => array(
					'smtp_host'       => 'sandbox.smtp.mailtrap.io',
					'smtp_port'       => 587,
					'smtp_encryption' => 'tls',
				),
			),
			'other'    => array(
				'label' => __( 'Other Provider', 'mail-doctor' ),
				'help'  => __( 'Enter your SMTP settings manually in the next step.', 'mail-doctor' ),
				'data'  => array(),
			),
		);
	}

	/**
	 * Retrieve a single provider preset.
	 *
	 * @param string $provider Provider key.
	 * @return array<string, mixed>
	 */
	public static function get( string $provider ): array {
		$providers = self::all();

		return $providers[ $provider ]['data'] ?? array();
	}

	/**
	 * Convenience shortcut for Gmail preset.
	 *
	 * @return array<string, mixed>
	 */
	public static function gmail(): array {
		return self::get( 'gmail' );
	}
}
