import { apiDelete, apiGet, apiPost } from '@/lib/http'
import type {
  TencentBrowserSessionData,
  TencentBrowserSessionSummaryData,
  TencentLoginType,
} from '@/types/tencent/session'

export interface CreateTencentBrowserSessionPayload {
  loginType?: TencentLoginType
}

export function createTencentBrowserSession(payload?: CreateTencentBrowserSessionPayload) {
  return apiPost<TencentBrowserSessionData>(
    '/api/v1/tencent/browser/session',
    payload as Record<string, unknown> | undefined,
  )
}

export function fetchTencentBrowserSession(sessionId: string) {
  return apiGet<TencentBrowserSessionData>(`/api/v1/tencent/browser/session/${sessionId}`)
}

export function fetchTencentBrowserSessionSummary(sessionId: string) {
  return apiGet<TencentBrowserSessionSummaryData>(
    `/api/v1/tencent/browser/session/${sessionId}/summary`,
  )
}

export function refreshTencentBrowserSessionPage(sessionId: string) {
  return apiPost<TencentBrowserSessionData>(`/api/v1/tencent/browser/session/${sessionId}/refresh`)
}

export function removeTencentBrowserSession(sessionId: string) {
  return apiDelete<Record<string, unknown>>(`/api/v1/tencent/browser/session/${sessionId}`)
}
