package topica.test;


import java.util.ArrayList;
import java.util.Scanner;



import topica.io.function;
import topica.moduel.CanBo;
import topica.moduel.GiangVien;
import topica.moduel.NhanVien;

public class Main  {
	
	
	
	
	static Scanner sc = new Scanner(System.in);
	static String pathName =  "C:\\Users\\ta\\Desktop\\javaProgram\\NhanVien";
	

	
	

	
	public static  void menu()
	{
		System.out.println("!---------------------------------------!");
		System.out.println("!1.Thêm nhân viên-----------------------!");
		System.out.println("!2.Hiển thị danh sách-------------------!");
		System.out.println("!3.Tìm kiếm theo ID---------------------!");
		System.out.println("!4.Sắp xếp danh sách theo 1:Tên , 2:Tuổi!");
		System.out.println("!5.Sửa khách hàng theo ID---------------!");
		System.out.println("!6.Xóa khách hàng theo ID---------------!");
		System.out.println("!7.Biến đổi sang map--------------------!");
		System.out.println("!7.Kết thúc chương trình----------------!");
		System.out.println("!---------------------------------------!");
	}
	
   public static void menu00()
   {
	   System.out.println("!------------------!");
	   System.out.println("!1.Thêm giảng viên-!");
	   System.out.println("!2.Thêm cán bộ-----!");
	   System.out.println("!------------------!");
	   boolean flag = true;
	   do {
		   System.out.print("Nhập loại nhân viên của bạn : ");
		   int choice = Integer.parseInt(sc.nextLine());
		
		   switch (choice) {
		case 1:
		{
		    themgiangvien();
			flag = false;
			break;
			
		}
		
		case 2:
		{
		    themcanbo();
			flag = false;
			break;
			
		}
		
		

		default:
		{
			System.out.println("Nhập sai vui lòng nhập lại !");
		}
		}
		   
		   
	} while (flag);
		   
	  
   }
	

   private static  void themcanbo() {
	// TODO Auto-generated method stub
	
	System.out.println("!-------------Nhập thông tin cán bộ-------------!");
		NhanVien nv = new GiangVien();
		nv.inputInformation();
		
	System.out.println("!------------------Kết thúc nhập-----------------!");
		
		boolean flag = function.addnhanvien(nv, pathName);
		if(flag)
		{
			System.out.println("Ghi thành công !");
		}
		else
		{
			System.out.println("Lỗi !");
		}
		
	
}

	
   private static  void themgiangvien() {
	// TODO Auto-generated method stub
		
		System.out.println("!-------------Nhập thông tin giảng viên------------!");
		NhanVien nv = new CanBo();
		nv.inputInformation();
		
		System.out.println("!------------------Kết thúc nhập-----------------!");
		
		
		boolean flag = function.addnhanvien(nv, pathName);
		if(flag)
		{
			System.out.println("Ghi thành công !");
		}
		else
		{
			System.out.println("Ghi thất bại !");
		}
		
	
}
	
	
	
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		menu();
		
		boolean flag = true;
		
		
		do {
			
			System.out.print("Nhập lựa chọn của bạn : ");
			int choice = Integer.parseInt(sc.nextLine());
			
			switch (choice) {
			case 1:
			{
				
				menu00();
			    break;
             }
			
			case 2 :
			{
				DisplayList();
				break;
			}
			
			case 3 :
			{
				find();
				break;
			}
			
			case 4 :
			{
				sapxep();
				break;
			}
			case 5 :
			{
				suathongtin();
				break;
			}
			
			case 6 :
			{
				xoathongtin();
				break;
			}
			
			
			case 7 :
			{
				System.out.println("Kết thúc chương trình !");
				flag = false;
				break;
			}
			
			
			
			default:
			{
				System.out.println("Nhập sai vui lòng nhập lại !");
				
			}
			
			
			}
			
			
		} while (flag);

	}

	
	
	
	
	
	private static void xoathongtin() {
		// TODO Auto-generated method stub
		ArrayList<NhanVien> arr = function.docFile(pathName);
		System.out.print("Nhập ID cần xóa : ");
		String s = sc.nextLine();
		if(function.findID(s, pathName)!=-1)
		{
			arr.remove(function.findID(s, pathName));
			function.luuFile(arr, pathName);
		}
		else
		{
			System.out.println("Không tìm thấy ID");
		}
			
		
		
	}

	private static void suathongtin() {
		// TODO Auto-generated method stub
		ArrayList<NhanVien> arr = function.docFile(pathName);
		System.out.print("Nhập mã nhân viên cần thay đổi : ");
		String s = sc.nextLine();
		int vt = function.findID(s, pathName);
		if(vt!=-1)
		{
			System.out.println("!------------!");
			System.out.println("!1.Cán bộ----!");
			System.out.println("!2.Giảng viên!");
			System.out.println("!------------!");
			System.out.print("Nhập lựa chọn của bạn : ");
			int choice = Integer.parseInt(sc.nextLine());
			
			
			switch (choice) {
			case 1:
			{
				GiangVien gv = new GiangVien();
				gv.inputInformation();
				arr.set(vt, gv);
				function.luuFile(arr, pathName);
				
				break;
				
			}
			
			case 2:
			{
				CanBo cb = new CanBo();
				cb.inputInformation();
				arr.set(vt, cb);
				function.luuFile(arr, pathName);
				break;
				
			}

			default:
				break;
			}
			
			
			
		}
		
		else
		{
			System.out.println("Không tìm thấy mã !");
		}
		
	}
			
			
			
			
		

	private static void sapxep() {
		// TODO Auto-generated method stub
		function.comparato(pathName);
		
		
		
	}

	
	
	private static void find() {
		// TODO Auto-generated method stub
		System.out.print("Nhập vào ID cần tìm : ");
		String str = sc.nextLine();
		  NhanVien nv = function.find(str, pathName);
		  if(nv==null)
		  {
			  System.out.println("Không tìm thấy ID");
			  
		  }
		  else
		  {
			  System.out.println(nv.toString());
		  }
		}
	
	
	

	private static  void DisplayList() {
		// TODO Auto-generated method stub
		ArrayList<NhanVien> arr = function.docFile(pathName);
		for (NhanVien nhanVien : arr) {
			System.out.println(nhanVien.toString());
		}
	
			
		
		
	}

}
