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

class Email_Notification_Settings_Model extends CI_Model {

    var $table = TBL_EMAIL_NOTIFICATION_SETTINGS;

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function get_all()
    {
        $this->db->order_by('id', 'asc');
        return $this->db->get($this->table)->result();
    }

    public function get_by_id($id)
    {
        return $this->db->get_where($this->table, ['id' => $id])->row();
    }

    /**
     * Get email settings by form key (e.g. 'health_checkup', 'appointment')
     */
    public function get_by_form_key($form_key)
    {
        return $this->db->get_where($this->table, ['form_key' => $form_key, 'status' => 1])->row();
    }

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