package report

import (
	"encoding/json"
	"fmt"
	"os"

	"qtransfer/internal/model"
)

func Write(path string, rep model.TransferReport) error {
	f, err := os.Create(path)
	if err != nil {
		return fmt.Errorf("create report file: %w", err)
	}
	defer f.Close()

	enc := json.NewEncoder(f)
	enc.SetIndent("", "  ")
	if err := enc.Encode(rep); err != nil {
		return fmt.Errorf("encode report: %w", err)
	}
	return nil
}
