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

import (
	e "simrs-vx/internal/domain/main-entities/prescription-item"
)

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

	data.Prescription_Id = inputSrc.Prescription_Id
	data.IsMix = inputSrc.IsMix
	data.Medicine_Code = inputSrc.Medicine_Code
	data.MedicineMix_Id = inputSrc.MedicineMix_Id
	data.Frequency = inputSrc.Frequency
	data.Dose = inputSrc.Dose
	data.Usage = inputSrc.Usage
	data.Interval = inputSrc.Interval
	data.IntervalUnit_Code = inputSrc.IntervalUnit_Code
	data.Quantity = inputSrc.Quantity
}

func countQty(input e.CreateDto) float64 {
	if input.Frequency != nil && input.Dose != 0 && input.IntervalMultiplier != nil {
		return (float64(*input.Frequency) * float64(input.Dose)) * float64(*input.IntervalMultiplier)
	}
	return 0
}
