import axios from 'axios';

// eslint-disable-next-line capitalized-comments
// const apiEnv = process.env.VUE_APP_TRANSFERS_V2_API;
const apiEnv = import.meta.env.VITE_APP_TAGSAMURAI_API;

const BASE_URL = window.Cypress ? 'https://localhost:9080' : apiEnv;

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export const api = ({ headers = {}, params = {} } = {}) => {
  const user = JSON.parse(localStorage.getItem('user') ?? '{}');

  const instance = axios.create({
    baseURL: `${BASE_URL}/fam/transfer/v2/transaction`,
    headers: {
      'Authorization': `Bearer ${user.token}`,
      'Content-type': 'application/json',
      ...headers,
    },
    params,
  });

  return instance;
};

type TypeOptions = 'nameOptions' | 'brandOptions' | 'modelOptions';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
const getTransactionLog = (id: string) => {
  return api().get(`/request/${id}/transaction-log`);
};

export default {
  getTransactionLog,
};
