package encounter

import (
	"fmt"
	sync "simrs-vx/internal/infra/sync-cfg"
	helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"

	e "simrs-vx/internal/domain/main-entities/encounter"
	elog "simrs-vx/internal/domain/sync-entities/log"
)

func Create(input *e.Encounter) error {
	return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
}

func CreateLog(input *elog.SimxLogDto) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := prefixEndpoint + "/log"
	return helper.DoJsonRequest(input, "POST", endpoint)
}

func Update(input *e.Encounter) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "PATCH", endpoint)
}

func Delete(input *e.DeleteDto) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "DELETE", endpoint)
}

func Checkin(input *e.Encounter) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v/checkin", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "PATCH", endpoint)
}

func Checkout(input *e.Encounter) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v/checkout", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "PATCH", endpoint)
}

func UpdateStatus(input *e.Encounter) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v/update-status", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "PATCH", endpoint)
}

func RequestSwitchUnit(input *e.Encounter) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v/req-switch-unit", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "PATCH", endpoint)
}

func ApproveSwitchUnit(input *e.ApproveCancelUnitDto) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v/approve-switch-unit", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "PATCH", endpoint)
}

func CancelSwitchUnit(input *e.ApproveCancelUnitDto) error {
	prefixEndpoint := getPrefixEndpoint()
	endpoint := fmt.Sprintf("%s/%v/cancel-switch-unit", prefixEndpoint, input.Id)
	return helper.DoJsonRequest(input, "PATCH", endpoint)
}

func getPrefixEndpoint() string {
	return fmt.Sprintf("%s%s/v1/encounter", sync.O.Host, sync.O.Prefix)
}
