<?php

namespace App\Models;

use CodeIgniter\Model;

class PpdbQuotaModel extends Model
{
    protected $table = 'ppdb_quotas';
    protected $primaryKey = 'id';
    protected $allowedFields = [
        'school_level','registration_path','quota','used'
    ];
    protected $useTimestamps = true;

    public function getQuota($level, $path)
    {
        return $this->where([
            'school_level' => $level,
            'registration_path' => $path
        ])->first();
    }

    public function incrementUsed($level, $path)
    {
        return $this->set('used', 'used+1', false)
            ->where([
                'school_level'=>$level,
                'registration_path'=>$path
            ])->update();
    }
}
