package ro.ase.cts.observer;

import java.util.ArrayList;
import java.util.Random;

public class StatieMeteo {
	//stare observabil
	String locatie;
	
	//lista observatori
	ArrayList<ClientMeteo> clienti = 
			new ArrayList<>();
	
	//interfata publica pt gestiunea observatorilor
	public void adaugaClient(ClientMeteo client){
		this.clienti.add(client);
	}
	
	public void stergeClient(ClientMeteo client){
		this.clienti.remove(client);
	}
	
	private void notificaClienti(StareVreme meteo){
		if(this.clienti!=null){
			for(ClientMeteo client : this.clienti)
				client.notificareMeteo(meteo);
		}
	}
	
	//metoda prin care se genereaza un eveniment
	public void inregistreazaDateMeteo(){
		float temp = (new Random()).nextInt(45);
		float vant = (new Random()).nextInt(200);
		float umiditate = (new Random()).nextInt(100);
		
		StareVreme meteo = 
				new StareVreme(
						temp,
						vant,
						umiditate,
						this.locatie);
		
		//notificare clienti
		this.notificaClienti(meteo);
	}

	public StatieMeteo(String locatie) {
		super();
		this.locatie = locatie;
	}
	
	
	
}
