package handlers

import (
	"github.com/fiskerinc/cloud-services/services/attendant/controllers"
	"github.com/fiskerinc/cloud-services/services/attendant/services"

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

	"github.com/pkg/errors"
)

func CarUpdateProgressStatus(db *services.DB, ka *services.KeepAwake, device common.Device, id string, data []byte) error {
	logger.Debug().Msgf("CarUpdateProgressStatus %v %s", device, id)

	clientPool := services.RedisClientPool()

	handler := controllers.NewCarUpdateProgress(clientPool, ka, db, device)
	if handler == nil {
		return errors.Errorf("NewCarUpdateProgress cannot handle device %v", device)
	}
	defer handler.Dispose()

	err := handler.Process(id, data)
	return err
}
