import br.edu.ifba.inf008.mediaCenter.model.Servidor;

public class MediaCenter{
    private Servidor[] servidores;
    
    
    public MediaCenter(){
        this.servidores = new Servidor[0];
    }    

    public double getTempoArmazenamento(long tamanho){
        double tempo = 0;
          Servidor destino = null;  
	      for(Servidor s : this.servidores)
	        if(s.temCapacidade(tamanho) && 
	          ((destino== null)|| (destino != null && destino.getLatenciaEscrita() > s.getLatenciaEscrita())))
	           destino = s;
	      tempo += destino.gravar(tamanho); 
        return tempo;
    }  

    
    public double getTempoLeitura(String id){
        Arquivo a = this.buscarArquivoPeloId(id);
        return a.getTempoRecuperacao();
    }      
    
    public void addServidor(Servidor servidor){
        Servidor[] novo = new Servidor[this.servidores.length + 1];
        for(int iCont = 0; iCont < this.servidores.length; iCont++)
          novo[iCont] = this.servidores[iCont];
        novo[novo.length - 1] = servidor;
        this.servidores = novo;
    }  
    
    public String toString(){
        String str = "Servidores\n";
        for(Servidor s : this.servidores)
          str += s.toString() + "\n";
        return str + "\n"; 
        
    }    
    
}
