'use server';
import { resolve } from '../../lib/server-container.js';
export async function listWorkItemStates(projectId) {
    if (!projectId?.trim()) {
        return { error: 'Project ID is required' };
    }
    try {
        const useCase = resolve('ManageWorkItemStatesUseCase');
        const states = await useCase.list(projectId);
        return { states };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list states';
        return { error: message };
    }
}
export async function createWorkItemState(input) {
    try {
        const useCase = resolve('ManageWorkItemStatesUseCase');
        const result = await useCase.create(input);
        if (!result.ok)
            return { error: result.error };
        return { state: result.state };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create state';
        return { error: message };
    }
}
export async function updateWorkItemState(stateId, fields) {
    if (!stateId?.trim()) {
        return { error: 'State ID is required' };
    }
    try {
        const useCase = resolve('ManageWorkItemStatesUseCase');
        const result = await useCase.update(stateId, fields);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to update state';
        return { error: message };
    }
}
export async function deleteWorkItemState(stateId) {
    if (!stateId?.trim()) {
        return { error: 'State ID is required' };
    }
    try {
        const useCase = resolve('ManageWorkItemStatesUseCase');
        const result = await useCase.delete(stateId);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to delete state';
        return { error: message };
    }
}
export async function reorderWorkItemStates(states) {
    try {
        const useCase = resolve('ManageWorkItemStatesUseCase');
        const result = await useCase.reorder(states);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to reorder states';
        return { error: message };
    }
}
