001/*
002 * JDrupes Builder
003 * Copyright (C) 2026 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.builder.core;
020
021import org.jdrupes.builder.api.BuildContext;
022import org.jdrupes.builder.api.Resource;
023import org.jdrupes.builder.api.ResourceProvider;
024import org.jdrupes.builder.api.ResourceRequest;
025import org.jdrupes.builder.api.ResourceType;
026
027/// Provided resources are identified by the [ResourceProvider]
028/// and the requested [Resource].
029///
030/// @param <T> the generic type
031/// @param provider the provider
032/// @param request the requested resources
033///
034public record ProviderInvocation<T extends Resource>(ResourceProvider provider,
035        ResourceRequest<T> request) {
036
037    private static class Launcher implements ResourceProvider {
038        private Launcher() {
039        }
040
041        @Override
042        public String name() {
043            return "Launcher";
044        }
045
046        @Override
047        public BuildContext context() {
048            throw new UnsupportedOperationException();
049        }
050
051        @Override
052        public <T extends Resource> ResourceRequest<T>
053                of(ResourceType<? extends T> type) {
054            throw new UnsupportedOperationException();
055        }
056
057        @Override
058        public String toString() {
059            return name();
060        }
061    }
062
063    /// The launching invocation.
064    public static final ProviderInvocation<?> LAUNCH
065        = new ProviderInvocation<>(new Launcher(),
066            new DefaultResourceRequest<>(new ResourceType<Resource>() {}));
067
068    @Override
069    public String toString() {
070        if (provider.equals(LAUNCH.provider)) {
071            return "Launcher";
072        }
073        return "[" + provider + " ← "
074            + ((DefaultResourceRequest<?>) request).toRequestedString() + "]";
075    }
076
077}