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

import (
	"errors"
	e "simrs-vx/internal/domain/main-entities/emergency"

	ere "simrs-vx/internal/domain/references/encounter"
)

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

	data.Encounter_Id = inputSrc.Encounter_Id
	data.Class_Code = inputSrc.Class_Code
}

func CheckClassCode(input *string) (ere.EmergencyClassCode, error) {
	if input != nil {
		subCode := ere.EmergencyClassCode(*input)
		switch subCode {
		case ere.ECCEmg, ere.ECCEon:
			return subCode, nil
		default:
			return "", errors.New("unknown sub class code")
		}
	}
	return "", errors.New("sub class code is nil")
}
