<?php

declare(strict_types=1);

namespace Tricks\LaravelTools\Data;

use Illuminate\Contracts\Mail\Attachable;
use Illuminate\Mail\Attachment;
use Spatie\LaravelData\Data;

final class AttachmentData extends Data implements Attachable
{
    public function __construct(
        public readonly string $Name,
        public readonly string $Type,
        public readonly string $Content,
    ) {
        //
    }

    public function toMailAttachment(): Attachment
    {
        return Attachment::fromData(
            fn (): string => base64_decode($this->Content),
            $this->Name
        )
            ->withMime($this->Type);
    }
}
