import axios, {AxiosHeaders, AxiosRequestConfig, AxiosRequestHeaders, InternalAxiosRequestConfig} from 'axios';
import * as SecureStore from 'expo-secure-store';

const apiClient = axios.create({
    baseURL: 'http://192.168.1.101:5000',
});

apiClient.interceptors.request.use(async (config) => {
    const accessToken = await SecureStore.getItemAsync('access_token');
    if (!config.headers) {
        config.headers = new AxiosHeaders();
    }
    if (accessToken) {
        config.headers.set('Authorization', `Bearer ${accessToken}`, true);
    }
    config.validateStatus = (status) => {
        return true
    };

    return config;
}, function (error) {
    return Promise.reject(error);
});

export default apiClient;
