<?php

declare(strict_types=1);

namespace Apexl\Io\Notifier\Notifiers;

use Apexl\Io\Notifier\Interfaces\EmailNotifierDriverInterface;
use Apexl\Io\Notifier\Interfaces\NotifierInterface;

abstract class EmailNotifier extends Notifier implements NotifierInterface
{
    abstract protected function to(): string;
    abstract protected function subject(): string;
    abstract protected function body(): string;

    public function __construct(protected EmailNotifierDriverInterface $driver)
    {
        parent::__construct();
    }

    public function send(): void
    {
        if ($this->shouldSend()) {
            $this->driver->send(
                $this->to(),
                $this->subject(),
                $this->body(),
                $this->attachments(),
                $this->embeddedImages(),
            );

            $this->logger->debug(sprintf('Sent email notification to %s', $this->to()));
        }
    }

    /**
     * @return array<array{path: string, name?: string}>
     */
    protected function attachments(): array
    {
        return [];
    }

    /**
     * @return array<array{path: string, cid: string, name?: string}>
     */
    protected function embeddedImages(): array
    {
        return [];
    }

    protected function shouldSend(): bool
    {
        return true;
    }
}
