package parser

import (
	"encoding/json"
	"os"

	"github.com/pingcap-inc/clinic/clinic_data_service/pkg/dto"
)

// ReadJSONOutput Read JSON file and convert to FinalOutput object
// filePath: Path to the JSON file
// Return value: FinalOutput object pointer and possible error
func ReadJSONOutput(filePath string) (*dto.FinalOutput, error) {
	// Read file content
	data, err := os.ReadFile(filePath)
	if err != nil {
		return nil, err
	}

	// Parse JSON to FinalOutput struct
	var finalOutput dto.FinalOutput
	err = json.Unmarshal(data, &finalOutput)
	if err != nil {
		return nil, err
	}

	return &finalOutput, nil
}
