/**
 * Copyright 2015 The original authors.
 * 
 * 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.
 * 
**/

package io.sundr.adapter.api;

import io.sundr.model.repo.DefinitionRepository;

public class AdapterContext {

  private final DefinitionRepository definitionRepository;

  public AdapterContext(DefinitionRepository definitionRepository) {
    this.definitionRepository = definitionRepository;
  }

  public DefinitionRepository getDefinitionRepository() {
    return definitionRepository;
  }
}

/**
 * Copyright 2015 The original authors.
 * 
 * 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.
 * 
**/

package io.sundr.adapter.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import io.sundr.model.AttributeKey;
import io.sundr.model.repo.DefinitionRepository;

public class AdapterContext {

  private final DefinitionRepository definitionRepository;
  private final Map<AttributeKey, Object> attributes;

  public AdapterContext(DefinitionRepository definitionRepository) {
    this(definitionRepository, new HashMap<>());
  }

  public AdapterContext(DefinitionRepository definitionRepository, Map<AttributeKey, Object> attributes) {
    this.definitionRepository = definitionRepository;
    this.attributes = attributes;
  }

  public Map<AttributeKey, Object> getAttributes() {
    if (attributes == null) {
      return null;
    }
    return Collections.unmodifiableMap(attributes);
  }

  public <T> T getAttribute(AttributeKey<T> key) {
    if (attributes == null) {
      return null;
    }
    return (T) attributes.get(key);
  }

  public <T> boolean hasAttribute(AttributeKey<T> key) {
    if (attributes == null) {
      return false;
    }
    return attributes.containsKey(key);
  }

  public DefinitionRepository getDefinitionRepository() {
    return definitionRepository;
  }
}

Introduce attributes to the AdapterContext