package com.sf._03_linked_list.demo1;

import java.util.LinkedList;

public class BankQueueSystem {
    //创建LinkedList  存储排队用户信息
    public static LinkedList<Customer> customers = new LinkedList<>();
    // 设置id
    public static Long nextId = 1L;

    /**
     * 普通用户取号
     * name : 取款人名称
     * businessType: 业务类型
     */
    public static void takeNumber(String name,String businessType){
        // 封装成一个Customer
        Customer customer = new Customer(nextId++,name,businessType);
        // 把customer 存到linkedList 当中 addLast();
        customers.addLast(customer);
        System.out.println("【取号成功】" + customer + "，当前排队人数：" + customers.size());
    }

    /**
     * vip 取号
     */
    public static void takeVipNumber(String name,String businessType){
        // 封装成一个Customer
        Customer customer = new Customer(nextId++,name,businessType);
        // 把customer 存到linkedList 当中 addLast();
        customers.addFirst(customer);
        System.out.println("【取号成功】" + customer + "，当前排队人数：" + customers.size());
    }



    /**
     * 叫号
     * 把队列的做表变元素移除并返回就可以了
     */
    public static void callNumber(){
        // 判断linkedList 是否有元素,如果没有元素提醒当前没有人排队
        if(customers.size() == 0){
            System.out.println("当前没有人排队办理业务");
            return;
        }
        // 如果元素个数大于0 , 移除头部元素
        Customer customer = customers.removeFirst();
        System.out.println("请编号"+ customer.getId() +"姓名: "+customer.getName()+"办理业务");
    }


    /**
     * 查看队列状态
     */
    public static void showQueueStatus(){
        //判空操作
        if(customers.size() == 0){
            System.out.println("当前没有任何人排队");
            return;
        }
        // 下一个叫号客户
        Customer nextCusotmer = customers.getFirst();
        // 最后一个叫号客户
        Customer lastCustomer = customers.getLast();
        System.out.println("下一号为:"+ nextCusotmer.getId() +"名称:"+ nextCusotmer.getName());
        System.out.println("最后一个号码为:"+ lastCustomer.getId() +"名称:"+ lastCustomer.getName());
        System.out.println("当前排队人数为:"+ customers.size());
    }

    public static void main(String[] args) {
        takeNumber("zhangsan","取款");
        takeNumber("lisi","转账");
        takeNumber("wangwu","存款");

        takeVipNumber("fanjialong","存款");

        showQueueStatus();
        // 叫号
//        callNumber();
//        callNumber();
//        callNumber();
//        callNumber();
    }
}
