<?php
namespace App\Models;
use CodeIgniter\Model;

class NoteModel extends Model
{
    protected $table          = 'notes';
    protected $primaryKey     = 'id';
    protected $useTimestamps  = false;
    protected $useSoftDeletes = false;
    protected $deletedField   = 'deleted_at';
    protected $allowedFields  = ['company_id','entity_type','entity_id','text','is_internal','pinned','created_by',
        'created_at', 'updated_at', 'deleted_at'];

    public function forEntity(int $companyId, string $entityType, int $entityId): array
    {
        return $this->where('company_id', $companyId)->where('entity_type', $entityType)->where('entity_id', $entityId)->whereNull('deleted_at')->orderBy('created_at', 'DESC')->findAll();
    }
}
