package composition

import (
	"encoding/json"
	"fmt"
)

// TODO: Sesuaikan dengan payload internal API
func MapToInternalAPI(dbData *CompositionDB, orgID string) map[string]interface{} {
	payload := map[string]interface{}{
		"composition_id": fmt.Sprintf("%d", dbData.IdxDokumen),
		"encounter_id":   fmt.Sprintf("%d", dbData.IdxDaftar),
		"patient_id":     dbData.NoMR.String,
	}
	return payload
}

func MapToSyncLog(idx int64, fhirID string, reqPayload interface{}, respBody []byte, status string, errMsg string) CompositionSyncLog {
	reqBytes, _ := json.MarshalIndent(reqPayload, "", "  ")
	return CompositionSyncLog{
		IdxDokumen:      idx,
		CompositionID:   fhirID,
		RequestPayload:  string(reqBytes),
		ResponsePayload: string(respBody),
		Status:          status,
		ErrorMessage:    errMsg,
	}
}
