import { NetworkService } from './NetworkService'
import { ServiceBase } from './ServiceBase'
import type { MatchSessionOptions } from '@/common/interfaces'

export class GameService extends ServiceBase {
  private networkService = new NetworkService()

  async createMatchSession(options: MatchSessionOptions) {
    const response = await this.networkService.post({
      uri: '/game/match',
      body: { options },
      auth: true,
    })
    const { sessionId } = response
    return sessionId
  }

  async cancelMatchSession(sessionId: string) {
    const response = await this.networkService.delete({
      uri: `/game/match/${sessionId}`,
      auth: true,
    })
    return response
  }

  async joinMatchSession(sessionId: string) {
    const response = await this.networkService.put({
      uri: `/game/match/${sessionId}`,
      auth: true,
    })
    return response
  }

  async listMatchSessions() {
    const response = await this.networkService.get({
      uri: '/game/match',
      auth: true,
    })
    return response
  }

  async getMatchSession(sessionId: string) {
    const response = await this.networkService.get({
      uri: `/game/match/${sessionId}`,
      auth: true,
    })
    return response
  }
}
