package com.hammurapi.store;

import java.util.Comparator;
import java.util.Iterator;
import java.util.concurrent.locks.Lock;

import com.hammurapi.extract.Extractor;
import com.hammurapi.extract.Predicate;
import com.hammurapi.store.Index.Type;

public class UnmodifiableStore<T,PK, S extends Store<T,PK,S>> implements Store<T,PK, S> {
	
	protected S master;

	public Iterator<T> iterator() {
		return master.iterator();
	}

	public Handle<T, PK, S> put(T obj, Predicate<T, S>... validators) {
		throw new UnsupportedOperationException();
	}

	public Iterable<T> getAll() {
		return master.getAll();
	}

	public int queryAll(QueryTask<T, PK, S> processor) {
		return master.queryAll(processor);
	}

	public T getByPrimaryKey(PK primaryKey) {
		return master.getByPrimaryKey(primaryKey);
	}

	public Iterable<T> get(Predicate<T, S> selector) {
		return master.get(selector);
	}

	public int query(Predicate<T, S> selector, QueryTask<T, PK, S> processor) {
		return master.query(selector, processor);
	}

	public <V> int query(Predicate<T, S> selector,
			Extractor<T, V, S> extractor,
			QueryTask<V, PK, S> processor) {
		return master.query(selector, extractor, processor);
	}

	public Lock readLock() {
		return master.readLock();
	}

	public Lock writeLock() {
		return master.writeLock();
	}

	public <V> int queryMultiple(Predicate<T, S> selector,
			Extractor<T, Iterable<V>, S> extractor,
			Predicate<V, S> valueSelector,
			QueryTask<V, PK, S> processor) {
		return master.queryMultiple(selector, extractor, valueSelector,	processor);
	}

	public <V> Iterable<V> get(Predicate<T, S> selector,
			Extractor<T, V, S> extractor, boolean ordered,
			Comparator<V> comparator) {
		return master.get(selector, extractor, ordered, comparator);
	}

	public <V> Iterable<V> getMultiple(Predicate<T, S> selector,
			Extractor<T, Iterable<V>, S> extractor,
			Predicate<V, S> valueSelector, boolean ordered,
			Comparator<V> comparator) {
		return master.getMultiple(selector, extractor, valueSelector, ordered, comparator);
	}

	public void clear() {
		throw new UnsupportedOperationException();
	}

	public boolean remove(T obj) {
		throw new UnsupportedOperationException();
	}

	public boolean removeByPrimaryKey(PK primaryKey) {
		throw new UnsupportedOperationException();
	}

	public int remove(Predicate<T, S> selector) {
		throw new UnsupportedOperationException();
	}

	public int update(Predicate<T, S> selector, UpdateTask<T, PK, S> updater) {
		throw new UnsupportedOperationException();
	}

	public <V, ST extends T> Index<T, ST, PK, V, S> addIndex(
			Predicate<T, S> predicate,
			Extractor<ST, V, S> extractor, Type type,
			boolean ordered, 
			Comparator<V> comparator) {
		throw new UnsupportedOperationException();
	}

	public Extractor<T, PK, S> getPrimaryKeyExtractor() {
		return master.getPrimaryKeyExtractor();
	}

	public S createView(Predicate<T, S> selector,	ViewType viewType) {
		return master.createView(selector, viewType);
	}

	public UnmodifiableStore(S master) {
		this.master = master;
	}

	protected S getMaster() {
		return master;
	}
	
	@Override
	public S createUnmodifiableFacade() {
		return (S) this;
	}
}
