import apiClient from "./apiClient";
import {Assembly} from "../types/assembly";

const router = '/assembly';

const assemblyApi = {
    create: async (orderId: number): Promise<{
        ok: boolean,
        message: string,
        assemblyId: number,
        statusCode: string
    }> => {
        let response = await apiClient.post(`${router}/create`, {orderId});
        return response.data;
    },
    close: async (assemblyId: number): Promise<{ ok: boolean, message: string }> => {
        let response = await apiClient.post(`${router}/close`, {assemblyId});
        return response.data;
    },
    cancel: async (): Promise<{ ok: boolean, message: string }> => {
        let response = await apiClient.post(`${router}/cancel`);
        return response.data;
    },
    getActive: async (): Promise<Assembly> => {
        let response = await apiClient.get(`${router}/getActive`);
        return response.data;
    },
    hasActive: async (): Promise<{ has: boolean }> => {
        let response = await apiClient.get(`${router}/hasActive`);
        return response.data;
    },
    updateState: async (assemblyId: number, state: number): Promise<{ ok: boolean }> => {
        let response = await apiClient.post(`${router}/updateState`, {assemblyId, state});
        return response.data;
    },
    confirm: async (assemblyId: number): Promise<{ ok: boolean, message: string }> => {
        let response = await apiClient.post(`${router}/confirm`, {assemblyId});
        return response.data;
    }
}

export default assemblyApi;