import axios from 'axios';
import { API_URL_USER } from '@/shared/api/api-url-user';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  BusinessPropertyParams,
  BusinessPropertyResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const businessProperty = (params: BusinessPropertyParams) => {
  let headerOptions = {
    menuId: 0,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<BusinessPropertyResponse>(API_URL_USER.businessProperty(), params, options),
  );
};

export const useBusinessPropertyMutation = (options?: UseMutationOptions<BusinessPropertyResponse, NiceAxiosError, BusinessPropertyParams>) => {
  const mutation = useMutation<BusinessPropertyResponse, NiceAxiosError, BusinessPropertyParams>({
    ...options,
    mutationFn: (params: BusinessPropertyParams) => businessProperty(params),
  });

  return {
    ...mutation,
  };
};
