type TokenResponse = {
  token: string
  expiresIn: number
}

export class TokenService {
  private baseUrl: string

  constructor(baseUrl: string) {
    this.baseUrl = baseUrl
  }

  async getToken(): Promise<TokenResponse> {
    try {
      const response = await fetch(`${this.baseUrl}/Auth/client/get-babylai-token`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        }
      })

      if (!response.ok) {
        throw new Error('Failed to fetch token')
      }

      const data = await response.json()
      return {
        token: data.token,
        expiresIn: data.expiresIn || 3600 // Default to 1 hour if not provided
      }
    } catch (error) {
      throw new Error('Failed to get authentication token')
    }
  }
}
