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

import (
	"errors"
	v "simrs-vx/internal/domain/main-entities/vehicle"
	rcl "simrs-vx/internal/domain/references/clinical"
	pl "simrs-vx/pkg/logger"
)

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

	data.Type_Code = &inputSrc.Type_Code
	data.PoliceNumber = inputSrc.PoliceNumber
	data.FrameNumber = inputSrc.FrameNumber
	data.RegNumber = inputSrc.RegNumber
	data.AvailableStatus = inputSrc.AvailableStatus
}

func validateRequest(input v.CreateDto, event *pl.Event) error {
	event.Status = "failed"
	event.ErrInfo = pl.ErrorInfo{
		Code: "data-validation-fail",
	}

	switch input.Type_Code {
	case rcl.VTCAmbulance, rcl.VTCTransport, rcl.VTCHearse:
		return nil
	default:
		event.ErrInfo.Detail = "type_code value is not recognized"
		event.ErrInfo.Raw = errors.New("type_code value is not recognized")
		return pl.SetLogError(event, input)
	}
}
