package project_1;
public class Course {

	private String name;
	private String id;
	private String whoTakeit;
	private String startTime;
	private String finishTime;
	private int maxNo;
	private String []a;
	private String course;
	private int noOfStudents;
	private int year;
	private LinkedList<Student> list = new LinkedList<>();

	public Course(String data) {
		this.course=data;

		DoEveryThing(data);
	}



	private void DoEveryThing(String data){
		try{
			a = data.split("#");

			this.name=a[0];
			this.id =a[1];
			this.whoTakeit=a[2];
			this.year=Integer.parseInt(whoTakeit);
			this.startTime = a[3];
			this.finishTime = a[4];
			this.maxNo = Integer.parseInt(a[5]);
			

		}

		catch (Exception e) {
			a=null;

		}
	}

	public boolean isValid(){

		if(a!=null)
		return a[1].startsWith("comp") || a[1].startsWith("COMP");

		return false;
		
	}




	public boolean add(Student newStudent){

		if (isValid() && thereIsEmptySite() && canTakeIt(newStudent) && newStudent.isThereFreeHours()) {

			list.addInsertion(newStudent);

			
			return true;

		}
		return false;
	}

	public boolean thereIsEmptySite(){
		return list.getSize() < this.maxNo ;
	}

	public boolean remove(Student st){
		if(isValid()){
			if( list.deleteData(st)){
				
				return true;
			}

		}
		return false;
	}

	public boolean canTakeIt(Student newStudent){
		return (newStudent.getYear().compareTo(this.getWhoTakeit())<=0);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getWhoTakeit() {
		return whoTakeit;
	}

	public void setWhoTakeit(String whoTakeit) {
		this.whoTakeit = whoTakeit;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getFinishTime() {
		return finishTime;
	}

	public void setFinishTime(String finishTime) {
		this.finishTime = finishTime;
	}

	public int getMaxNo() {
		return maxNo;
	}

	public void setMaxNo(int maxNo) {
		this.maxNo = maxNo;
	}

	public LinkedList<Student> getList() {
		return list;
	}


	public String getCourse() {
		return course;
	}

	public void printStudentsInfo(){
		list.print();
	}




	@Override
	public String toString() {
		return "Name=" + name + ", id=" + id + ", startTime=" + startTime + ", finishTime=" + finishTime
				+ ", noOfStudents=" + getNoOfStudents() + ", year=" + year ;
	}



	public int compareTo(Course data){
		if(this.year > data.getYear()){
			return 1;
		}
		if(this.year < data.getYear()){
			return -1;
		}
		else
			return 0;
	}



	public int getNoOfStudents() {
		return list.getSize();
	}



	public int getYear() {
		return year;
	}



}
