package careplan

import (
	"encoding/json"
	"fmt"
)

// MapToInternalAPI memetakan data database menjadi payload untuk Internal API
// TODO: Sesuaikan dengan JSON Payload endpoint CarePlan Anda
func MapToInternalAPI(dbData *CarePlanDB, orgID string) map[string]interface{} {
	payload := map[string]interface{}{
		"careplan_id":  fmt.Sprintf("%d", dbData.IdxRencana),
		"encounter_id": fmt.Sprintf("%d", dbData.IdxDaftar),
		"patient_id":   dbData.NoMR.String, // Perlu diganti IHS Number di service
	}
	return payload
}

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