package handlers

import (
	"net/http"

	"otaupdate/controllers"
	"otaupdate/services"

	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/go-pg/pg/v10/orm"
	"github.com/google/uuid"
	"github.com/gorilla/schema"
)

// @deprecated
// HandleSubscriptionFeatureDelete godoc
// @Summary Delete subscription feature
// @Description Delete subscription feature data. Requires delete permissions
// @Accept  json
// @Produce  json
// @Param Authorization header string false "Bearer <ID token>"
// @Param Api-Key header string false "<API token>"
// @Param id query string true "Subscription feature id"
// @Success 200 {object} common.JSONMessage
// @Failure 400 {object} common.JSONError "Bad request"
// @Failure 401 {object} common.JSONError "Unauthorized"
// @Failure 503 {object} common.JSONError "Service unavailable"
// @Router /subscriptionfeature [delete]
func HandleSubscriptionFeatureDelete(w http.ResponseWriter, r *http.Request) {
	subscriptionFeatureDelete.Handle(w, r)
}

var subscriptionFeatureDelete = controllers.NewDelete(&subscriptionFeatureDeleteHelper{})

type subscriptionFeatureDeleteHelper struct {
	SubscriptionFeatureHelper
}

func (h *subscriptionFeatureDeleteHelper) ParseDeleteQueryParams(r *http.Request) interface{} {
	req := common.SubscriptionFeature{}
	decoder := schema.NewDecoder()

	decoder.SetAliasTag("json")
	decoder.Decode(&req, r.URL.Query())

	return &req
}

func (h *subscriptionFeatureDeleteHelper) QueryDelete(model interface{}) (orm.Result, error) {
	return services.GetDB().GetSubFeatures().Delete(model.(*common.SubscriptionFeature))
}

type SubscriptionFeatureDeleteRequest struct {
	ID uuid.UUID `validate:"required"`
}
