package xyz.danielcortes.controllers.editorial;

import java.util.List;
import xyz.danielcortes.framework.BaseTableModel;
import xyz.danielcortes.models.Editorial;
import xyz.danielcortes.repository.EditorialRepository;
import xyz.danielcortes.views.editorial.EditorialListPanel;

public class EditorialListController {
  private EditorialListPanel view;
  private EditorialRepository editorialRepository;

  public EditorialListController(EditorialListPanel view) {
    this.view = view;
    this.editorialRepository = new EditorialRepository();
    this.loadEditorialTable();
  }

  public void reload() {
    this.loadEditorialTable();
  }

  private void loadEditorialTable(){
    List<Editorial> editoriales = this.editorialRepository.getAll();
    BaseTableModel<Editorial> model = this.view.getEditorialModel();
    model.addRows(editoriales);
  }

  public EditorialListPanel getView() {
    return view;
  }
}
