package com.devlab.app.data.api

import okhttp3.Interceptor
import okhttp3.Response

class AuthInterceptor(private val token: String) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request().newBuilder()
            .addHeader("Authorization", "Bearer $token")
            .addHeader("Accept", "application/json")
            .build()
        val response = chain.proceed(request)

        if (response.code == 401 && token.isNotBlank()) {
            SessionManager.invalidateSession()
        }

        return response
    }
}
