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

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

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

	data.Medication_Id = inputSrc.Medication_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.IsRedeemed = inputSrc.IsRedeemed
	data.Quantity = inputSrc.Quantity
	data.Note = inputSrc.Note

	if inputSrc.IntervalMultiplier != nil {
		data.Quantity = countQty(*inputSrc)
	}
}

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
}
