<?php

namespace App\Models;

use CodeIgniter\Model;

class ModelResepObatDetail extends Model
{
    protected $table            = 'resep_obat_detail';
    protected $primaryKey       = 'id';
    protected $allowedFields    = ['id_resep', 'id_obat', 'dosis', 'jumlah', 'aturan_pakai'];

    public function getByResep($id_resep)
    {
        return $this->select('resep_obat_detail.*, obat.nama_obat, obat.satuan')
            ->join('obat', 'obat.id_obat = resep_obat_detail.id_obat')
            ->where('id_resep', $id_resep)
            ->findAll();
    }

    public function tambahData($data)
    {
        return $this->insert($data);
    }

    public function deleteByResep($id_resep)
    {
        return $this->where('id_resep', $id_resep)->delete();
    }
}
