package api

import (
	"github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/common"
)

type HostageRescued struct {
	Frame                  int     `json:"frame"`
	Tick                   int     `json:"tick"`
	RoundNumber            int     `json:"roundNumber"`
	PlayerSteamID64        uint64  `json:"playerSteamId"`
	IsPlayerControllingBot bool    `json:"isPlayerControllingBot"`
	HostageEntityId        int     `json:"hostageEntityId"`
	X                      float64 `json:"x"`
	Y                      float64 `json:"y"`
	Z                      float64 `json:"z"`
}

func newHostageRescued(analyzer *Analyzer, hostage *common.Hostage) *HostageRescued {
	parser := analyzer.parser

	return &HostageRescued{
		Frame:                  parser.CurrentFrame(),
		Tick:                   analyzer.currentTick(),
		RoundNumber:            analyzer.currentRound.Number,
		PlayerSteamID64:        hostage.Leader().SteamID64,
		IsPlayerControllingBot: hostage.Leader().IsControllingBot(),
		HostageEntityId:        hostage.Entity.ID(),
		X:                      hostage.Position().X,
		Y:                      hostage.Position().Y,
		Z:                      hostage.Position().Z,
	}
}
