<?php declare(strict_types=1);
// Christo Lochenberg Developments | info@christodev.co.za | +27 61 523 9126

class Role {
    private Database $db;

    public function __construct() {
        $this->db = new Database();
    }

    public function getRoles(): array {
        $this->db->query('SELECT * FROM staff_roles ORDER BY role_name ASC');
        return $this->db->resultSet();
    }

    public function getRoleById(int $id): object|bool {
        $this->db->query('SELECT * FROM staff_roles WHERE id = :id');
        $this->db->bind(':id', $id);
        return $this->db->single();
    }

    public function addRole(array $data): bool {
        $this->db->query('INSERT INTO staff_roles (role_name, description) VALUES (:role_name, :description)');
        $this->db->bind(':role_name', $data['role_name']);
        $this->db->bind(':description', $data['description']);
        return $this->db->execute();
    }

    public function updateRole(array $data): bool {
        $this->db->query('UPDATE staff_roles SET role_name = :role_name, description = :description WHERE id = :id');
        $this->db->bind(':id', $data['id']);
        $this->db->bind(':role_name', $data['role_name']);
        $this->db->bind(':description', $data['description']);
        return $this->db->execute();
    }

    public function deleteRole(int $id): bool {
        $this->db->query('DELETE FROM staff_roles WHERE id = :id');
        $this->db->bind(':id', $id);
        return $this->db->execute();
    }
}