import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import {
    DetailResponse,
    TitleInfo,
    DetailInfo
} from '../../model/types';
import {
    useMutation,
    UseMutationOptions
} from '@tanstack/react-query';
import { ExtensionAccountHolderSearchDetailParams, ExtensionAccountHolderSearchDetailResponse } from '../../model/account-holder-search/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionAccountHolderSearchDetail = (params: ExtensionAccountHolderSearchDetailParams) => {
    let headerOptions = {
        menuId: 60,
        apiType: 'SELECT'
    };
    let options = {
        headers: {
            'X-User-Agent': getHeaderUserAgent(headerOptions)
        }
    };
    return resultify(
        axios.post<ExtensionAccountHolderSearchDetailResponse>(API_URL_ADDITIONAL_SERVICE.extensionAccountHolderSearchDetail(), params, options),
    );
};

export const useExtensionAccountHolderSearchDetailtMutation = (options?: UseMutationOptions<ExtensionAccountHolderSearchDetailResponse, NiceAxiosError, ExtensionAccountHolderSearchDetailParams>) => {
    const mutation = useMutation<ExtensionAccountHolderSearchDetailResponse, NiceAxiosError, ExtensionAccountHolderSearchDetailParams>({
        ...options,
        mutationFn: (params: ExtensionAccountHolderSearchDetailParams) => extensionAccountHolderSearchDetail(params),
    });

    return {
        ...mutation,
    };
};