<?php
class SessionDebriefRow
{
    public $sessionId = -1;
	public int $sessionTypeId = -1;
	public $sessionType = "";
	public $sessionName = "";
	public $sessionDate = "";
	public $mapName = "";
	public $scenarioName = "";
	public bool $sessionSuccessful = false;
	public float $sessionDuration = 0.0;
	public int $triggerTypeId = -1;
	public $triggerType = "";
	public int $shooterId = -1;
    public $shooterName = "";
	public int $shooterRoleId = -1;
	public $shooterRole = "";
    public int $shotIndex = -1;
    public int $reactId = -1;
    public int $reactModeId = -1;
    public $reactMode = "";
    public int $reactTypeId = -1;
    public $reactType = "";
    public int $targetUserId = -1;
    public $targetUserName = "";
	public int $targetRoleId = -1;
	public $targetRole = "";
    public $targetName = "";
    public $targetBoneName = "";
    public bool $targetKilled = false;
    public float $hitLocationX = 0.0;
    public float $hitLocationY = 0.0;
    public $hitLocationTag = "";
    public float $hitPrecision = 0.0;
    public float $hitTargetDistance = 0.0;
    public float $reactTime = 0.0;
    public float $timeStamp = 0.0;
    public int $nbHit = 0;
    public int $nbKilled = 0;
    
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public static function withRow (array $row)
	{
        $instance = new self();
        $instance->readRow($row);
        return $instance;
    }

    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function readRow (array $row)
	{
        $this->sessionId = $row['SessionId'];
		$this->sessionTypeId = $row['SessionTypeId'];
		$this->sessionType = $row['SessionType'];
		$this->sessionName = $row['SessionName'];
		$this->sessionDate = $row['SessionDate'];
		$this->mapName = $row['MapName'];
		$this->scenarioName = $row['ScenarioName'];
		$this->sessionSuccessful = $row['SessionSuccessful'] == 1;
		$this->sessionDuration = (float)$row['SessionDuration'];
		$this->triggerTypeId = (int)$row['TriggerTypeId'];
		$this->triggerType = $row['TriggerType'];
		$this->shooterId = (int)$row['ShooterId'];
		$this->shooterName = $row['ShooterName'];
		$this->shooterRoleId = (int)$row['ShooterRoleId'];
		$this->shooterRole = $row['ShooterRole'];
		$this->shotIndex = (int)$row['ShotIndex'];
		$this->reactId = (int)$row['ReactId'];
		$this->reactModeId = (int)$row['ReactModeId'];
		$this->reactMode = $row['ReactMode'];
		$this->reactTypeId = (int)$row['ReactTypeId'];
		$this->reactType = $row['ReactType'];
		$this->targetUserId = (int)$row['TargetUserId'];
		$this->targetUserName = $row['TargetUserName'];
		$this->targetRoleId = (int)$row['TargetRoleId'];
		$this->targetRole = $row['TargetRole'];
		$this->targetName = $row['TargetName'];
		$this->targetBoneName = $row['TargetBoneName'];
		$this->targetKilled = $row['TargetKilled'] == 1;
		$this->hitLocationX = (float)$row['HitLocationX'];
		$this->hitLocationY = (float)$row['HitLocationY'];
		$this->hitLocationTag = $row['HitLocationTag'];
		$this->hitPrecision = (float)$row['HitPrecision'];
		$this->hitTargetDistance = (float)$row['HitTargetDistance'];
		$this->reactTime = (float)$row['ReactionTime'];
		$this->timeStamp = (float)$row['TimeStamp'];
		$this->nbHit = (int)$row['NbHit'];
		$this->nbKilled = (int)$row['NbKilled'];
    }


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public function toArray () : array
	{
		return array (
			"SessionId" => (int)$this->sessionId,
			"SessionTypeId" => (int)$this->sessionTypeId,
			"SessionTypeAsString" => $this->sessionType,
			"SessionName" => $this->sessionName,
			"SessionDateAsString" => $this->sessionDate,
			"MapName" => $this->mapName,
			"ScenarioName" => $this->scenarioName,
			"SessionSuccessful" => $this->sessionSuccessful,
			"SessionDuration" => (float)$this->sessionDuration,
			"TriggerTypeId" => (int)$this->triggerTypeId,
			"TriggerTypeAsString" => $this->triggerType,
			"ShooterId" => (int)$this->shooterId,
			"ShooterName" => $this->shooterName,
			"ShooterRoleId" => (int)$this->shooterRoleId,
			"ShooterRoleAsString" => $this->shooterRole,
			"ShotIndex" => (int)$this->shotIndex,
			"ReactId" => (int)$this->reactId,
			"ReactModeId" => (int)$this->reactModeId,
			"ReactModeAsString" => $this->reactMode,
			"ReactTypeId" => (int)$this->reactTypeId,
			"ReactTypeAsString" => $this->reactType,
			"TargetUserId" => (int)$this->targetUserId,
			"TargetUserName" => $this->targetUserName,
			"TargetRoleId" => (int)$this->targetRoleId,
			"TargetRoleAsString" => $this->targetRole,
			"TargetName" => $this->targetName,
			"TargetBoneName" => $this->targetBoneName,
			"TargetKilled" => $this->targetKilled,
			"HitLocationX" => (float)$this->hitLocationX,
			"HitLocationY" => (float)$this->hitLocationY,
			"HitLocationTag" => $this->hitLocationTag,
			"HitPrecision" => (float)$this->hitPrecision,
			"HitTargetDistance" => (float)$this->hitTargetDistance,
			"ReactionTime" => (float)$this->reactTime,
			"TimeStamp" => (float)$this->timeStamp,
			"NbHit" => (int)$this->nbHit,
			"NbKilled" => (int)$this->nbKilled
		);
	}
}






class SessionDebriefRowWithTotals
{
	public SessionDebriefRow $sessionRow;
	public int $nbFiredShotsByUser = 0;
	public int $nbEnemyHitsByUser = 0;
	public int $nbCivilHitsByUser = 0;
	public int $nbPoliceHitsByUser = 0;
	public int $nbMissedShotsByUser = 0;
	//public int $nbFiredShotsByIA = 0;
	public int $nbEnemyHitsByIA = 0;
	public int $nbCivilHitsByIA = 0;
	public int $nbPoliceHitsByIA = 0;
	//public int $nbMissedShotsByIA = 0;

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public static function withRow (array $row)
	{
        $instance = new self();
        $instance->readRow($row);
        return $instance;
    }

    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function readRow (array $row)
	{
        $this->sessionRow = SessionDebriefRow::withRow($row);
		
		if ($row['ReactTypeId'] == -1)
			$this->nbMissedShotsByUser = (int)$row['NbShotsOfType'];
		else if ($row['ShooterRoleId'] == 0)
		{
			$this->nbFiredShotsByUser = (int)$row['NbShotsOfType'];
			switch ($row['ReactTypeId'])
			{
				case 0 : $this->nbEnemyHitsByUser = (int)$row['NbShotsOfType']; break;
				case 1 : $this->nbCivilHitsByUser = (int)$row['NbShotsOfType']; break;
				case 2 : $this->nbPoliceHitsByUser = (int)$row['NbShotsOfType']; break;
			}
		}
		else if ($row['ShooterRoleId'] == 3)	// IA
		{
			//$this->nbFiredShotsByIA = (int)$row['NbShotsOfType'];
			switch ($row['ReactTypeId'])
			{
				case 0 : $this->nbEnemyHitsByIA = (int)$row['NbShotsOfType']; break;
				case 1 : $this->nbCivilHitsByIA = (int)$row['NbShotsOfType']; break;
				case 2 : $this->nbPoliceHitsByIA = (int)$row['NbShotsOfType']; break;
			}
				
		}
    }


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public function toArray () : array
	{
		return array (
			"session" => $this->sessionRow->toArray(),
			"NbFiredShotsByUser" => (int)$this->nbFiredShotsByUser,
			"NbEnemyHitsByUser" => (int)$this->nbEnemyHitsByUser,
			"NbCivilHitsByUser" => (int)$this->nbCivilHitsByUser,
			"NbPoliceHitsByUser" => (int)$this->nbPoliceHitsByUser,
			"NbMissedShotsByUser" => (int)$this->nbMissedShotsByUser,
			//"NbFiredShotsByIA" => (int)$this->nbFiredShotsByIA,
			"NbEnemyHitsByIA" => (int)$this->nbEnemyHitsByIA,
			"NbCivilHitsByIA" => (int)$this->nbCivilHitsByIA,
			"NbPoliceHitsByIA" => (int)$this->nbPoliceHitsByIA
			//"NbMissedShotsByIA" => (int)$this->nbMissedShotsByIA
		);
	}
}
?>