<?php


namespace App\Model\Facades\Readers;


use App\Model\Exceptions\Db\RecordNotFoundException;
use App\Model\Interfaces\IEntity;

abstract class BaseReader
{
    public function validateEntity($entity)
    {
        if ($entity === null) {
            throw new RecordNotFoundException();
        }
    }

    // todo: find out why I need this...
    public static function getPrimaryKey($entity)
    {
        if (is_numeric($entity)) {
            return $entity; // assume it is primary key
        }

        if ($entity instanceof IEntity) {
            return $entity->getId();
        }
    }
}