<?php


namespace App\Http\Traits;


use App\Models\AppSession;

trait KeysIdsTrait
{
	public function getId ($object)
	{
		if( !$object) {
			return false;
		}
		if( !$object->id) {
			return false;
		}
		return $object->id;
	}
	
	public function getIid ($object)
	{
		if( !$object) {
			return false;
		}
		if( !$object->iid) {
			return false;
		}
		return $object->iid;
	}
	
	public function getUid ($object)
	{
		if( !$object) {
			return false;
		}
		if( !$object->uid) {
			return false;
		}
		return $object->uid;
	}
	
	public function saveForeignKey ($object)
	{
		return $object->id;
	}
	
	public function getCurrentSessionId ()
	{
		return request()->cookie("credo_session_key");
	}
	
	public function getCurrentAgentId ()
	{
		$sessionKey = $this->getCurrentSessionId();
		$appSession = AppSession::where("session_key", $sessionKey)->first();
		return $appSession->agent->uid;
	}
}
