package reference

import (
	"net/http"

	e "simrs-vx/internal/domain/bpjs-entities/reference"
	u "simrs-vx/internal/use-case/bpjs-use-case/reference"

	d "github.com/karincake/dodol"
	rw "github.com/karincake/risoles"
)

func GetListProvince(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	dto.ReferenceType = e.RTProvince
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListCities(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	pValue := rw.ValidateString(w, "provinceCode", r.PathValue("provinceCode"))
	if pValue == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "provinceCode is required"}, nil)
	}
	dto.ReferenceType = e.RTCities
	dto.PathValue1 = pValue
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListDistrict(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	pValue := rw.ValidateString(w, "regencyCode", r.PathValue("regencyCode"))
	if pValue == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "regencyCode is required"}, nil)
	}
	dto.ReferenceType = e.RTDistrict
	dto.PathValue1 = pValue
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListDiagnose(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	pValue := rw.ValidateString(w, "keyword", r.PathValue("keyword"))
	if pValue == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "keyword is required"}, nil)
	}
	dto.ReferenceType = e.RTDiagnose
	dto.PathValue1 = pValue
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListDiagnosePrb(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	dto.ReferenceType = e.RTDiagnosePrb
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListMedicinePrb(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	pValue := rw.ValidateString(w, "keyword", r.PathValue("keyword"))
	if pValue == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "keyword is required"}, nil)
	}
	dto.ReferenceType = e.RTMedicinePrb
	dto.PathValue1 = pValue
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListUnit(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	pValue := rw.ValidateString(w, "unitCode", r.PathValue("unitCode"))
	if pValue == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "unitCode is required"}, nil)
	}
	dto.ReferenceType = e.RTUnit
	dto.PathValue1 = pValue
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListHealthcare(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	pValue1 := rw.ValidateString(w, "healthcare", r.PathValue("healthcare"))
	if pValue1 == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "healthcare is required"}, nil)
	}
	pValue2 := rw.ValidateString(w, "healthcareType", r.PathValue("healthcareType"))
	if pValue2 == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "healthcareType is required"}, nil)
	}
	dto.ReferenceType = e.RTHealthcare
	dto.PathValue1 = pValue1
	dto.PathValue2 = pValue2
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}

func GetListDoctor(w http.ResponseWriter, r *http.Request) {
	dto := e.ReadListDto{}
	pValue1 := rw.ValidateString(w, "serviceType", r.PathValue("serviceType"))
	if pValue1 == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "serviceType is required"}, nil)
	}
	pValue2 := rw.ValidateString(w, "serviceDate", r.PathValue("serviceDate"))
	if pValue2 == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "serviceDate is required"}, nil)
	}
	pValue3 := rw.ValidateString(w, "specialistCode", r.PathValue("specialistCode"))
	if pValue3 == "" {
		rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "specialistCode is required"}, nil)
	}
	dto.PathValue1 = pValue1
	dto.PathValue2 = pValue2
	dto.PathValue3 = pValue3
	dto.ReferenceType = e.RTDoctor
	res, err := u.ReadList(dto)
	rw.DataResponse(w, res, err)
}
