<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Services_model extends CI_Model {

    private $table = 'kns1_services';

    // Get all services with department name
    public function count_all()
{
    return $this->db->count_all('kns1_services'); // table name
}

    public function get_all() {
        $this->db->select('s.*, d.name as department_name');
        $this->db->from('kns1_services s');
        $this->db->join('kns1_departments d', 'd.id = s.department_id', 'left');
        $this->db->order_by('s.id', 'DESC');
        return $this->db->get()->result();
    }

    // Get single service
    public function get($id) {
        $this->db->order_by('s.id', 'ASC');
        return $this->db->get_where($this->table, ['id' => $id])->row();

    }

    // Insert new service
    public function insert($data) {
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }

    // Update service
    public function update($id, $data) {
        $this->db->where('id', $id);
        return $this->db->update($this->table, $data);
    }

    // Delete service
    public function delete($id) {
        $this->db->where('id', $id);
        return $this->db->delete($this->table);
    }
}
