<?php

namespace App\Models;

use CodeIgniter\Model;

class LearningDeviceTpModel extends Model
{
    protected $table            = 'learning_device_tps';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $allowedFields    = ['learning_device_id', 'code', 'description', 'allocated_hours', 'semester', 'sort_order', 'chapter'];

    protected $useTimestamps = true;
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';

    // Ambil semua TP milik satu perangkat diurutkan sesuai urutan ATP
    public function getByDevice(int $deviceId)
    {
        return $this->where('learning_device_id', $deviceId)
                    ->orderBy('sort_order', 'ASC')
                    ->findAll() ?? [];
    }
}
