<?php
/**
 * Default mailer (PHP mail() transport).
 *
 * Renamed from PhpMailer.php to DefaultMailer.php to avoid a filename
 * collision with WordPress core's bundled PHPMailer library, which the
 * WordPress.org Plugin Check tool flags under library_core_files.
 *
 * @package NimblyMail\SMTP
 */

namespace NimblyMail\SMTP\Mailers;

use PHPMailer\PHPMailer\PHPMailer as LibPhpMailer;

defined( 'ABSPATH' ) || exit;

/**
 * Class DefaultMailer
 *
 * Wrapper for the default WordPress/PHP mail transport.
 *
 * @since 1.0.0 Renamed from PhpMailer to DefaultMailer to avoid a filename
 *              collision with WordPress core's bundled PHPMailer library.
 */
class DefaultMailer extends AbstractMailer {

    /**
     * {@inheritdoc}
     */
    public function get_slug(): string {
        return 'php';
    }

    /**
     * {@inheritdoc}
     */
    public function get_title(): string {
        return __( 'Default (PHP)', 'nimblymail-smtp' );
    }

    /**
     * Get the mailer description shown in the mailer-cards selector.
     *
     * @since 1.0.0
     *
     * @return string
     */
    public function get_description(): string {
        return __( 'Built-in PHP mail function.', 'nimblymail-smtp' );
    }

    /**
     * Get settings fields for this mailer.
     *
     * DefaultMailer has no configurable fields; returning an empty array
     * signals SettingsProvider to skip this mailer when building the
     * Connection tab.
     *
     * @since 1.0.0 Migrated to section-shaped return for SettingsProvider loop.
     *
     * @return array Empty array — no settings for this mailer.
     */
    public function get_settings_fields(): array {
        return array();
    }

    /**
     * Configure the PHPMailer instance for this transport.
     *
     * Explicitly switches PHPMailer back to the PHP mail() transport and
     * clears any SMTP settings left by another plugin (e.g. Fluent SMTP,
     * WP Mail SMTP) that may have hooked `phpmailer_init` at an earlier
     * priority. Without this reset, an active third-party SMTP plugin
     * would keep the instance in SMTP mode and attempts to send would
     * still route to the other plugin's server.
     *
     * @since 1.0.0 Reset transport and clear SMTP state to override conflicting plugins.
     *
     * @param LibPhpMailer $phpmailer The PHPMailer instance.
     */
    public function configure( LibPhpMailer $phpmailer ): void {
        $phpmailer->isMail();
        $phpmailer->Host        = '';
        $phpmailer->Port        = 25;
        $phpmailer->SMTPAuth    = false;
        $phpmailer->SMTPSecure  = '';
        $phpmailer->SMTPAutoTLS = false;
        $phpmailer->Username    = '';
        $phpmailer->Password    = '';
    }
}
