package fr.titionfire.ffsaf.net2.packet;

import fr.titionfire.ffsaf.net2.ServerCustom;
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
import org.jboss.logging.Logger;

import java.util.Collection;
import java.util.HashMap;

public class RClub {
    private static final Logger LOGGER = Logger.getLogger(RClub.class);

    final CIA<Long> findByIdOptionalClub = new CIA<>(Long.class, (client_Thread, message) -> {
        try {
            SimpleClubModel clubModel = ServerCustom.getInstance().clubService.findByIdOptionalClub(message.data());
            client_Thread.sendRepTo(clubModel, message);
        } catch (Throwable e) {
            LOGGER.error(e.getMessage(), e);
            client_Thread.sendErrTo(e.getMessage(), message);
        }
    });

    final IAction findAllClub = (client_Thread, message) -> {
        try {
            Collection<SimpleClubModel> clubModels = ServerCustom.getInstance().clubService.findAllClub();
            client_Thread.sendRepTo(clubModels, message);
        } catch (Throwable e) {
            LOGGER.error(e.getMessage(), e);
            client_Thread.sendErrTo(e.getMessage(), message);
        }
    };

    public static void register(HashMap<String, IAction> iMap) {
        RClub rClub = new RClub();

        iMap.put("findByIdOptionalClub", rClub.findByIdOptionalClub);
        iMap.put("findAllClub", rClub.findAllClub);
    }
}
