<?php

declare(strict_types=1);

namespace App\Framework\AsyncExamples\Mail;

/**
 * E-Mail Datenklasse
 */
final readonly class Email
{
    public function __construct(
        public string $to,
        public string $subject,
        public string $body,
        public string $fromEmail,
        public string $fromName = '',
        public array $cc = [],
        public array $bcc = [],
        public bool $isHtml = false,
        public array $attachments = []
    ) {
    }

    /**
     * Erstellt HTML-E-Mail
     */
    public static function html(string $to, string $subject, string $body, string $fromEmail, string $fromName = ''): self
    {
        return new self($to, $subject, $body, $fromEmail, $fromName, isHtml: true);
    }

    /**
     * Erstellt Text-E-Mail
     */
    public static function text(string $to, string $subject, string $body, string $fromEmail, string $fromName = ''): self
    {
        return new self($to, $subject, $body, $fromEmail, $fromName, isHtml: false);
    }

    /**
     * Fügt CC-Empfänger hinzu
     */
    public function withCc(array $cc): self
    {
        return new self(
            $this->to,
            $this->subject,
            $this->body,
            $this->fromEmail,
            $this->fromName,
            array_merge($this->cc, $cc),
            $this->bcc,
            $this->isHtml,
            $this->attachments
        );
    }

    /**
     * Fügt BCC-Empfänger hinzu
     */
    public function withBcc(array $bcc): self
    {
        return new self(
            $this->to,
            $this->subject,
            $this->body,
            $this->fromEmail,
            $this->fromName,
            $this->cc,
            array_merge($this->bcc, $bcc),
            $this->isHtml,
            $this->attachments
        );
    }
}
