/*
 * Copyright (c) 2010-2026 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.binding.fineoffsetweatherstation.internal.domain;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetGatewayConfiguration;
import org.openhab.binding.fineoffsetweatherstation.internal.handler.ThingStatusListener;
import org.openhab.binding.fineoffsetweatherstation.internal.service.ELVGatewayQueryService;
import org.openhab.binding.fineoffsetweatherstation.internal.service.EcowittHttpGatewayQueryService;
import org.openhab.binding.fineoffsetweatherstation.internal.service.FineOffsetGatewayQueryService;
import org.openhab.binding.fineoffsetweatherstation.internal.service.GatewayQueryService;

/**
 * The protocol defining the way the data is parsed
 *
 * @author Andreas Berger - Initial contribution
 */
@NonNullByDefault
public enum Protocol {
    DEFAULT(FineOffsetGatewayQueryService::new, null),
    ELV(ELVGatewayQueryService::new, ParserCustomizationType.ELV),
    HTTP_ECOWITT(EcowittHttpGatewayQueryService::new, null);

    private final GatewayQueryServiceFactory queryServiceFactory;
    private final @Nullable ParserCustomizationType parserCustomizationType;

    Protocol(GatewayQueryServiceFactory queryServiceFactory,
            @Nullable ParserCustomizationType parserCustomizationType) {
        this.queryServiceFactory = queryServiceFactory;
        this.parserCustomizationType = parserCustomizationType;
    }

    public @Nullable ParserCustomizationType getParserCustomizationType() {
        return parserCustomizationType;
    }

    public GatewayQueryService getGatewayQueryService(FineOffsetGatewayConfiguration config,
            @Nullable ThingStatusListener thingStatusListener) {
        return queryServiceFactory.newInstance(config, thingStatusListener);
    }

    private interface GatewayQueryServiceFactory {
        GatewayQueryService newInstance(FineOffsetGatewayConfiguration config,
                @Nullable ThingStatusListener thingStatusListener);
    }
}
