import { adapterRegistry } from '../adapters/adapter-registry';
import type { StorageType, ResourceData, CreateResourceData } from '../types';

export async function getResourceByFileId(fileId: string): Promise<{ status: string; resource?: ResourceData }> {
	const adapter = adapterRegistry.getDatabaseAdapter();
	return adapter.getResourceByFileId(fileId);
}

export async function deleteResource(id: string): Promise<ResourceData> {
	const adapter = adapterRegistry.getDatabaseAdapter();
	return adapter.deleteResource(id);
}

export async function deleteFailedUploadingResource(expirationPeriod: number): Promise<{ count: number }> {
	const adapter = adapterRegistry.getDatabaseAdapter();
	return adapter.deleteFailedUploadingResource(expirationPeriod);
}

export async function updateResource(id: string, data: any): Promise<ResourceData> {
	const adapter = adapterRegistry.getDatabaseAdapter();
	return adapter.updateResource(id, data);
}

export async function migrateResourcesStorageType(
	fromStorageType: StorageType,
	toStorageType: StorageType,
): Promise<{ count: number }> {
	const adapter = adapterRegistry.getDatabaseAdapter();
	return adapter.migrateResourcesStorageType(fromStorageType, toStorageType);
}

export async function createResource(data: CreateResourceData): Promise<ResourceData> {
	const adapter = adapterRegistry.getDatabaseAdapter();
	return adapter.createResource(data);
}

export async function updateResourceStatus(
	fileId: string,
	status: string,
	additionalData?: any,
): Promise<ResourceData> {
	const adapter = adapterRegistry.getDatabaseAdapter();
	return adapter.updateResourceStatus(fileId, status, additionalData);
}
