# Copyright 2024-2025 Acme Gating, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import urllib

from zuul.driver import Driver, ConnectionInterface, ProviderInterface
from zuul.driver.static import (
    staticconnection,
    staticmodel,
    staticprovider,
    staticendpoint,
)

from zuul.provider import EndpointCacheMixin


class StaticDriver(Driver, EndpointCacheMixin,
                   ConnectionInterface, ProviderInterface):
    name = 'static'
    _endpoint_class = staticendpoint.StaticProviderEndpoint

    def getConnection(self, name, config):
        return staticconnection.StaticConnection(self, name, config)

    def getProvider(self, zk_client, connection, tenant_name,
                    canonical_name, provider_config, system_id):
        return staticprovider.StaticProvider(
            self, zk_client, connection, tenant_name,
            canonical_name, provider_config, system_id)

    def getProviderClass(self):
        return staticprovider.StaticProvider

    def getProviderSchema(self):
        return staticprovider.StaticProviderSchema().getProviderSchema()

    def getProviderSchemaClass(self):
        return staticprovider.StaticProviderSchema

    def getProviderNodeClass(self):
        return staticmodel.StaticProviderNode

    def getEndpoint(self, provider):
        endpoint_id = urllib.parse.quote_plus(
            provider.connection.connection_name)
        return self.getEndpointById(
            endpoint_id,
            create_args=(self, provider.zk_client, provider.connection,
                         provider.system_id))

    def stop(self):
        self.stopEndpoints()
