package microfolie.db.table;

import java.util.List;
import java.util.Optional;

import db.DatabaseTable;
import db.annotation.DbTable;
import entity.Usager;

@DbTable(name = "Usager", entity = Usager.class)
public class UsagerTable extends DatabaseTable<Usager> {
	
	private static UsagerTable instance;
	
	private UsagerTable() {
		// Private constructor for singleton
	}
	
	public Usager getByCode(String code) {
		List<Usager> list = getByField("CODE", code);
		if(list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}
	
	public Optional<Usager> findByCode(String code) {
		Usager obj = getByCode(code);
		if (obj == null) {
			return Optional.empty();
		}
		return Optional.of(obj);
	}
	
	public static UsagerTable getInstance() {
		if(instance == null) {
			instance = new UsagerTable();
		}
		return instance;
	}	

}
