'use server';
import { resolve } from '../../lib/server-container.js';
export async function listSavedViews(projectId) {
    if (!projectId?.trim()) {
        return { error: 'Project ID is required' };
    }
    try {
        const useCase = resolve('ManageSavedViewsUseCase');
        const views = await useCase.list(projectId);
        return { views };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list saved views';
        return { error: message };
    }
}
export async function createSavedView(input) {
    try {
        const useCase = resolve('ManageSavedViewsUseCase');
        const result = await useCase.create(input);
        if (!result.ok)
            return { error: result.error };
        return { view: result.view };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create saved view';
        return { error: message };
    }
}
export async function updateSavedView(viewId, fields) {
    if (!viewId?.trim()) {
        return { error: 'View ID is required' };
    }
    try {
        const useCase = resolve('ManageSavedViewsUseCase');
        const result = await useCase.update(viewId, fields);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to update saved view';
        return { error: message };
    }
}
export async function deleteSavedView(viewId) {
    if (!viewId?.trim()) {
        return { error: 'View ID is required' };
    }
    try {
        const useCase = resolve('ManageSavedViewsUseCase');
        const result = await useCase.delete(viewId);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to delete saved view';
        return { error: message };
    }
}
