package tech.easyflow.ai.node.filegeneration;

import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * Markdown 文件渲染器。
 *
 * @author Codex
 * @since 2026-04-18
 */
@Component
public class MarkdownFileRenderer implements DocumentRenderer {

    @Override
    public TargetFormat getTargetFormat() {
        return TargetFormat.MD;
    }

    @Override
    public boolean supports(SourceFormat sourceFormat) {
        return sourceFormat == SourceFormat.PLAIN_TEXT || sourceFormat == SourceFormat.MARKDOWN;
    }

    @Override
    public FileGenerationResult render(FileGenerationRequest request) {
        byte[] bytes = (request.getContent() == null ? "" : request.getContent()).getBytes(StandardCharsets.UTF_8);
        return new FileGenerationResult(
                request.getFileName(),
                TargetFormat.MD.getValue(),
                TargetFormat.MD.getContentType(),
                bytes
        );
    }
}
