/* eslint-disable import/no-unresolved */
/* eslint-disable import/order */


import { sageService } from '@/service/sageService';
import { ContactRequest, Contacts } from '@/types/clientType';
import { createAsyncThunk } from '@reduxjs/toolkit';


/**
 * get all contacts clients
 */
export const contactsClient = createAsyncThunk(
  'contact/contactsClient',
  async (numero: string): Promise<Contacts[]> => {
    try {
      return await sageService.contacts(numero);
    } catch (err) {
      throw err;
    }
  }
);




/**
 * add contact
 */
export const addContactClient = createAsyncThunk(
  'contact/addContactClient',
  async (data: ContactRequest): Promise<Contacts> => {
    try {
      return await sageService.addContact(data);
    } catch (err) {
      throw err;
    }
  }
);





/**
 * update contact
 */
export const updateContactClient = createAsyncThunk(
  'contact/updateContactClient',
  async (
    {
      contact_numero,
      data,
    }: { contact_numero: number; data: ContactRequest }
  ): Promise<Contacts> => {
    return await sageService.updateContact(contact_numero, data);
  }
);




/**
 * add contact fournisseur
 */
export const addContactFournisseur = createAsyncThunk(
  'contact/addContactFournisseur',
  async (data: ContactRequest): Promise<Contacts> => {
    try {
      return await sageService.addContact(data);
    } catch (err) {
      throw err;
    }
  }
);





/**
 * update contact fournisseur
 */
export const updateContactFournisseur = createAsyncThunk(
  'contact/updateContactFournisseur',
  async (
    {
      contact_numero,
      data,
    }: { contact_numero: number; data: ContactRequest }
  ): Promise<Contacts> => {
    return await sageService.updateContact(contact_numero, data);
  }
);
