<?php

namespace App\Models\Backoffice\Support;

use App\Models\Backoffice\Support\Collections\BaseCollection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

abstract class BaseModel extends Model
{
    public function newCollection(array $models = [])
    {
        return new BaseCollection($models);
    }

    public function keyExists($key)
    {
        $camelKey = Str::camel($key);

        return (
            array_key_exists($key, $this->attributes)
            || $this->hasGetMutator($key)
            || array_key_exists($key, $this->relations)
            || method_exists($this, $camelKey));
    }
}
