import { AnyJson } from '~/types/interfaces'
import {QUERY_TYPE} from "~/types/enums";
import DataProvider from "~/services/data/dataProvider";

/**
 * Composable function
 * @category composables/data
 * @param $dataProvider
 */
export function useAccessesProvider($dataProvider: DataProvider){

  /**
   * Retourne les personnes physique selon leur nom et prénom
   * @param research
   */
  async function getPhysicalByFullName(research: string): Promise<Array<AnyJson>>{
    if(research){
      const response = await $dataProvider.invoke({
        type: QUERY_TYPE.DEFAULT,
        url: `api/access_people`,
        listArgs: {
          filters:[
            {key: 'person.isPhysical', value: 1},
            {key: 'fullname', value: research}
          ]
        }
      })
      return response.data
    }
    return []
  }

  return {
    getPhysicalByFullName
  }
}
