package handlers

import (
	"net/http"

	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/httphandlers"
	"github.com/julienschmidt/httprouter"

	"github.com/fiskerinc/cloud-services/pkg/logger"
)

// Need this so the swagger can use m
var _ = common.APIToken{}

// HandleVehicleDelete godoc
// @Summary Delete vehicle
// @Description Delete vehicle 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 vin path string true "VIN"
// @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 /vehicle/{vin} [delete]
func HandleVehicleDeleteHoneyPot(w http.ResponseWriter, r *http.Request) {
	params := httprouter.ParamsFromContext(r.Context())
	vin := params.ByName("vin")
	username := httphandlers.GetClientID(r)

	logger.Error().Msgf("user %s attempted to delete car %s", username, vin)
}

/* func HandleVehicleDelete(w http.ResponseWriter, r *http.Request) {
	var car common.Car
	params := httprouter.ParamsFromContext(r.Context())
	car.VIN = params.ByName("vin")

	err := validator.ValidateNonRequired(car)
	if loggerdataresp.BadDataErrorResp(w, err, http.StatusBadRequest) {
		return
	}

	client, err := services.GetMongoClient()
	if loggerdataresp.BadDataErrorResp(w, err, http.StatusServiceUnavailable) {
		return
	}

	removeVinFromFleets(car.VIN, client)

	_, err = services.GetDB().GetCars().Delete(&car)
	if loggerdataresp.BadDataErrorResp(w, err, http.StatusServiceUnavailable) {
		return
	}

	err = client.GetVehicles().DeleteVehicle(&mongo.Vehicle{VIN: car.VIN})
	if loggerdataresp.BadDataErrorResp(w, err, http.StatusServiceUnavailable, logger.MongoDeleteErrorCheck) {
		return
	}

	utils.RespJSON(w, http.StatusOK, common.JSONMessage{
		Message: "Deleted",
	})
} */

/* func removeVinFromFleets(vin string, client mongo.Client) error {
	fleets, err := client.GetVehicles().GetFleetsForVehicle(vin, "", &queries.PageQueryOptions{})
	if err != nil {
		return err
	}

	if len(fleets) == 0 {
		return nil
	}

	for _, fleet := range fleets {
		err = client.GetFleets().DeleteVehiclesFromFleet(fleet, []string{vin})
		if err != nil {
			return err
		}

	}
	ResetVehiclesConfigCache([]string{vin})

	return nil
} */
