import { GetOrder, CreateOrder } from "../../models/api";

import { api } from "./api";
import { extractBodyFromResponse, extractErrorMessageFromResponse } from "./utils";

export const landingApi = api.injectEndpoints({
  endpoints: ({ mutation, query }) => ({
    getOrder: query<GetOrder.Response, GetOrder.Params>({
      query: ({ orderId }) => `/order/${orderId}`,
      transformResponse: extractBodyFromResponse<GetOrder.Response>,
      transformErrorResponse: extractErrorMessageFromResponse,
    }),
    createOrder: mutation<CreateOrder.Response, CreateOrder.Params>({
      query: ({ body }) => ({
        url: `/order/create`,
        body,
        method: 'POST'
      }),
      transformResponse: extractBodyFromResponse<CreateOrder.Response>,
      transformErrorResponse: extractErrorMessageFromResponse,
    }),
  })
});
