// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: MIT

use crate::memory::alloc;
use alloc::string::String;
use alloc::vec::Vec;
use spin::Mutex;

#[allow(dead_code)]
pub static PROCESS_TABLE: Mutex<Vec<Process>> = Mutex::new(Vec::new());
// Currently running process. Invalid once the referenced process dies and
// is destructed.
#[allow(dead_code)]
pub static CURRENT_PROCESS: Mutex<Option<&Process>> = Mutex::new(None);

#[allow(dead_code)]
pub struct Process {
    /// Unique process ID.
    proc_id: u32,
    /// ID of the parent process.
    parent_proc_id: u32,
    /// Human readable name of the process, should be the command.
    name: String,
    /// The base address of the process stack within its memory region.
    stack_base_addr: usize,
    /// The length of the stack. This, plus the start address, is the stack size.
    stack_length: usize,
    /// The stack pointer, which is relative to the memory region start.
    stack_pointer: usize,
    /// Process priority. Lower number is higher priority.
    priority: u16,
}

#[allow(dead_code)]
pub fn context_switch() -> ! {
    todo!("Context switch")
}

#[allow(dead_code)]
pub enum ProcessState {
    // The process is the one being currently executed.
    Running,
    // The process is blocked by a syscall.
    Waiting,
    // The process is voluntarily napping until an alarm goes off.
    Sleeping,
    // The process has been "paused", and can be resumed or killed.
    Suspended,
}
