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

class Profil_model extends CI_Model {

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

    public function get_warga_by_user($user_id) {
        // Relasi: users.warga_id → warga.id
        $this->db->select('w.*');
        $this->db->from('warga w');
        $this->db->join('users u', 'u.warga_id = w.id', 'inner');
        $this->db->where('u.id', $user_id);
        return $this->db->get()->row();
    }

    public function update_user($user_id, $data) {
        $this->db->where('id', $user_id);
        return $this->db->update('users', $data);
    }

    public function update_warga($warga_id, $data) {
        $this->db->where('id', $warga_id);
        return $this->db->update('warga', $data);
    }
}