'use client'

import { IBaseResponse } from '@/@core/types/api'
import { ICreateTable, ITable } from '@/types/data/table'
import { request } from '@/utils'
import { TABLES_LIST_QUERY_KEY } from './useGetTablesList'
import { useCustomMutation } from '@/hooks/api'

export const useCreateTable = () => {
  return useCustomMutation<ICreateTable, IBaseResponse<ITable>>(
    ['tables-create'],
    payload =>
      request<IBaseResponse<ITable>, ICreateTable>({
        url: '/tables',
        method: 'POST',
        data: payload
      }),
    {
      invalidateQueries: [TABLES_LIST_QUERY_KEY]
    }
  )
}
