#ifndef LCAMERA_DEV_CAMERA_MANAGER_STATE_H
#define LCAMERA_DEV_CAMERA_MANAGER_STATE_H

#include <lcameraDev.h>
#include <cameraSession.h>
#include <libcamera/camera_manager.h>
#include <map>
#include <memory>
#include <spinscale/co/coQutex.h>
#include <spinscale/componentThread.h>
#include <spinscale/sharedResourceGroup.h>
#include <string>
#include <vector>

namespace lcamera_dev {

struct CameraManagerResources
{
	std::unique_ptr<libcamera::CameraManager> cameraManager;
	std::map<std::string, std::shared_ptr<CameraSession>> sessionsByCameraId;
};

struct LcameraDevState
{
	LcameraDevState()
	: managerState("lcameraDev::CameraManager")
	{}

	bool isInitialized = false;
	std::shared_ptr<sscl::ComponentThread> componentThread;
	sscl::SharedResourceGroup<sscl::co::CoQutex, CameraManagerResources>
		managerState;
};

LcameraDevState& getLcameraDevState();

void lcameraDevMain(
	const std::shared_ptr<sscl::ComponentThread>& componentThread);
void lcameraDevExit();

std::vector<std::shared_ptr<libcamera::Camera>> listLibcameraCameras();

sscl::co::ViralNonPostingInvoker<CameraIdentityRecord>
resolveDeviceSelectorCReq(const std::string& deviceSelector);

sscl::co::ViralNonPostingInvoker<LcameraDevGetOrCreateResult>
getOrCreateDeviceSessionCReq(const std::string& deviceSelector);

sscl::co::ViralNonPostingInvoker<void>
releaseDeviceSessionCReq(
	const std::shared_ptr<CameraSession>& deviceSession);

sscl::co::ViralNonPostingInvoker<std::vector<LcameraDevCameraInfo>>
enumerateCamerasCReq();

} // namespace lcamera_dev

#endif // LCAMERA_DEV_CAMERA_MANAGER_STATE_H
