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

class FileModel extends Model
{
    protected $table          = 'files';
    protected $primaryKey     = 'id';
    protected $useSoftDeletes = false;
    protected $deletedField   = 'deleted_at';
    protected $allowedFields  = ['company_id','entity_type','entity_id','filename','original_name','mime_type','file_size','disk','disk_path','thumbnail_path','is_public','uploaded_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();
    }
}
