package CHAPTER09;

import java.util.PriorityQueue;

class Patient implements Comparable<Patient> {
    private String name;
    private int priority; // 낮을수록 높은 우선순위

    public Patient(String name, int priority) {
        this.name = name;
        this.priority = priority;
    }

    public String getName() {
        return name;
    }

    @Override
    public int compareTo(Patient other) {
        return Integer.compare(this.priority, other.priority); // 우선순위 비교
    }

    @Override
    public String toString() {
        return "환자 이름: " + name + ", 우선순위: " + priority;
    }
}

public class PriorityQueueExam {
    public static void main(String[] args) {
        // PriorityQueue 생성
        PriorityQueue<Patient> queue = new PriorityQueue<>();

        // 환자 추가
        queue.add(new Patient("Alice", 3)); // 우선순위 3
        queue.add(new Patient("Bob", 1));   // 우선순위 1
        queue.add(new Patient("Charlie", 2)); // 우선순위 2

        // 대기 목록 출력
        System.out.println("현재 대기 목록:");
        for (Patient patient : queue) {
            System.out.println(patient);
        }

        // 우선순위에 따라 처리
        System.out.println("\n처리 순서:");
        while (!queue.isEmpty()) {
            Patient next = queue.poll(); // 가장 높은 우선순위 환자 처리
            System.out.println(next.getName() + " 환자를 처리 중...");
        }
    }
}
