package encounter

import (
	"net/http"

	rw "github.com/karincake/risoles"
	// ua "github.com/karincake/tumpeng/auth/svc"

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

	u "simrs-vx/internal/use-case/simgos-sync-use-case/new/encounter"
)

type myBase struct{}

var O myBase

func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
	dto := e.Encounter{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}
	res, err := u.Create(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) CreateLog(w http.ResponseWriter, r *http.Request) {
	dto := esync.SimxLogDto{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}
	res, err := u.CreateSimxLog(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
	dto := e.Encounter{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}

	res, err := u.Update(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
	id := rw.ValidateInt(w, "id", r.PathValue("id"))
	if id <= 0 {
		return
	}

	dto := e.DeleteDto{}
	dto.Id = uint(id)

	res, err := u.Delete(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) Checkin(w http.ResponseWriter, r *http.Request) {
	dto := e.Encounter{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}

	res, err := u.CheckIn(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) Checkout(w http.ResponseWriter, r *http.Request) {
	dto := e.Encounter{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}

	res, err := u.CheckOut(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) UpdateStatus(w http.ResponseWriter, r *http.Request) {
	dto := e.Encounter{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}

	res, err := u.UpdateStatus(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
	dto := e.Encounter{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}

	res, err := u.RequestSwitchUnit(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
	dto := e.ApproveCancelUnitDto{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}

	res, err := u.ApproveSwitchUnit(dto)
	rw.DataResponse(w, res, err)
}

func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) {
	dto := e.ApproveCancelUnitDto{}
	if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
		return
	}

	res, err := u.CancelSwitchUnit(dto)
	rw.DataResponse(w, res, err)
}
