<?php

namespace MintyPHP\Service\Mail;

use MintyPHP\Repository\Mail\MailLogRepositoryInterface;
use MintyPHP\Service\Settings\SettingsSmtpGateway;

class MailServicesFactory
{
    private ?MailService $mailService = null;
    private ?MailLogService $mailLogService = null;

    public function __construct(
        private readonly MailRepositoryFactory $mailRepositoryFactory,
        private readonly SettingsSmtpGateway $settingsSmtpGateway
    ) {
    }

    public function createMailLogRepository(): MailLogRepositoryInterface
    {
        return $this->mailRepositoryFactory->createMailLogRepository();
    }

    public function createMailService(): MailService
    {
        return $this->mailService ??= new MailService(
            $this->createMailLogRepository(),
            $this->createSettingsSmtpGateway()
        );
    }

    public function createMailLogService(): MailLogService
    {
        return $this->mailLogService ??= new MailLogService($this->createMailLogRepository());
    }

    private function createSettingsSmtpGateway(): SettingsSmtpGateway
    {
        return $this->settingsSmtpGateway;
    }
}
