'use server';
import { resolve } from '../../lib/server-container.js';
export async function listCustomProperties(projectId) {
    if (!projectId?.trim()) {
        return { error: 'Project ID is required' };
    }
    try {
        const useCase = resolve('ManageCustomPropertiesUseCase');
        const properties = await useCase.list(projectId);
        return { properties };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list custom properties';
        return { error: message };
    }
}
export async function createCustomProperty(input) {
    try {
        const useCase = resolve('ManageCustomPropertiesUseCase');
        const result = await useCase.create(input);
        if (!result.ok)
            return { error: result.error };
        return { property: result.property };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create custom property';
        return { error: message };
    }
}
export async function updateCustomProperty(propertyId, fields) {
    if (!propertyId?.trim()) {
        return { error: 'Property ID is required' };
    }
    try {
        const useCase = resolve('ManageCustomPropertiesUseCase');
        const result = await useCase.update(propertyId, fields);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to update custom property';
        return { error: message };
    }
}
export async function deleteCustomProperty(propertyId) {
    if (!propertyId?.trim()) {
        return { error: 'Property ID is required' };
    }
    try {
        const useCase = resolve('ManageCustomPropertiesUseCase');
        const result = await useCase.delete(propertyId);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to delete custom property';
        return { error: message };
    }
}
