<?php

namespace App\Models;

use CodeIgniter\Model;

class SignatureModel extends Model
{
    protected $table = 'signatures';
    protected $primaryKey = 'id';
    protected $returnType = 'array';
    protected $useAutoIncrement = true;
    protected $protectFields = true;
    protected $allowedFields = ['signable_type', 'signable_id', 'role', 'name', 'png_path', 'signed_at'];
    protected $useTimestamps = false;

    public function findFor(string $type, int $id, string $role): ?array
    {
        return $this->where('signable_type', $type)
            ->where('signable_id', $id)
            ->where('role', $role)
            ->orderBy('id', 'DESC')
            ->first() ?: null;
    }
}
