import api from 'src/config/api';
import {
  type FormSection,
  type Task,
} from 'src/pages/dashboard/serviceManagement/types';

export const initForm = (tag: number | string, token: string) =>
  api.post<FormSection>(
    `dynamic-forms/${tag}/progressions`,
    {},
    {
      params: { token },
    },
  );

export const updateProgress = (
  tag: string,
  progressionId: string,
  body: unknown,
) =>
  api.patch<FormSection>(
    `dynamic-forms/${tag}/progressions/${progressionId}`,
    body,
  );

export const getForm = (tag: string, answerId: number, token: string) =>
  api.get<FormSection>(`dynamic-forms/${tag}/answers/${answerId}`, {
    params: {
      token,
      withDetails: true,
    },
  });

export const createForm = (catalogItemId: string, formAnswerId: number) =>
  api.post<Task>('/workflows/tasks', {
    catalogItemId,
    formAnswerId,
  });
