<?php

namespace App\Models;

use CodeIgniter\Model;

class ViolationRuleModel extends Model
{
    protected $table            = 'violation_rules';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $allowedFields    = ['category_id', 'code', 'description', 'severity', 'points'];
    protected $useTimestamps    = true;

    public function getAllWithCategory()
    {
        return $this->select('violation_rules.*, violation_categories.name as category_name')
            ->join('violation_categories', 'violation_categories.id = violation_rules.category_id')
            ->orderBy('violation_rules.code', 'ASC')
            ->findAll();
    }
}
