import type { Game } from './apiResponseTypes'
import type { Player } from './playersService'
import { SITE_URL } from './utilities'

export interface Decision {
  id: number,
  game: Game,
  season: number,
  week: number,
  game_num: number,
  pitcher: Player,
  win: number,
  loss: number,
  hold: number,
  is_save: number,
  b_save: number,
  irunners: number,
  irunners_scored: number,
  rest_ip: number,
  rest_required: number,
  is_start: false
}

export async function fetchLast2DecisionsByPlayerId(seasonNumber: number, playerId: number): Promise<Decision[]> {
  const response = await fetch(`${SITE_URL}/api/v3/decisions?season=${seasonNumber}&player_id=${playerId}&limit=2`)

  const decisionsResponse: {
    count: number
    decisions: Decision[]
  } = await response.json()

  return decisionsResponse.decisions
}


