/*
DESCRIPTION:
Any functions that are used internally by the use-case
*/
package installation

import (
	"encoding/json"
	e "simrs-vx/internal/domain/main-entities/installation"
	erc "simrs-vx/internal/domain/references/common"
	esimgos "simrs-vx/internal/domain/simgos-entities/m-instalasi"
	esync "simrs-vx/internal/domain/sync-entities/installation"
	esyncLog "simrs-vx/internal/domain/sync-entities/log"
)

func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T) (data esimgos.MInstalasi) {
	var inputSrc *e.CreateDto
	if inputT, ok := any(input).(*e.CreateDto); ok {
		inputSrc = inputT
	} else {
		inputTemp := any(input).(*e.UpdateDto)
		inputSrc = &inputTemp.CreateDto
	}

	data.Nama_Instalasi = inputSrc.Name
	data.Status_Rawat_Inap = 0
	data.St_Aktif = 1

	return
}

func setDataSimxLog(input *esyncLog.SimxLogDto) (data esync.InstallationSimxLog) {
	// encode to JSON
	jsonData, _ := json.MarshalIndent(input.Payload, "", "  ")
	jsonString := string(jsonData)

	var status erc.ProcessStatusCode
	if input.IsSuccess {
		status = erc.PSCSuccess
	} else {
		status = erc.PSCFailed
		if input.ErrMessage != nil {
			data.ErrMessage = input.ErrMessage
		}
	}

	data.Value = &jsonString
	data.Date = &now
	data.Status = status

	return
}

func setDataSimxLink(simxId, simgosId uint) (data esync.InstallationLink) {
	data.Simx_Id = simxId
	data.Simgos_Id = simgosId
	return
}
