using System.Text;
using DocumentFormat.OpenXml.Packaging;

namespace KiMailOrderAgent.Attachments;

public class DocxTextExtractor
{
    public string Extract(byte[] content)
    {
        using var stream = new MemoryStream(content);
        using var doc = WordprocessingDocument.Open(stream, false);

        var sb = new StringBuilder();

        var body = doc.MainDocumentPart?.Document.Body;

        if (body == null)
            return "";

        sb.AppendLine(body.InnerText);

        return sb.ToString();
    }
}
