package ch.elexis.core.test.service;

import java.time.LocalDate;
import java.util.Optional;

import ch.elexis.core.model.IContact;
import ch.elexis.core.model.IMandator;
import ch.elexis.core.model.IPatient;
import ch.elexis.core.model.IPerson;
import ch.elexis.core.model.IUser;
import ch.elexis.core.model.builder.IContactBuilder;
import ch.elexis.core.model.builder.IUserBuilder;
import ch.elexis.core.services.IContext;
import ch.elexis.core.services.IModelService;
import ch.elexis.core.types.Gender;

public class TestContext implements IContext {
	
	private IModelService coreModelService;
	
	private IMandator mandator;
	private IUser user;
	
	public TestContext(IModelService coreModelService){
		this.coreModelService = coreModelService;
		
		IPerson _mandator = new IContactBuilder.PersonBuilder(coreModelService, "Elisa",
			"Mandatore", LocalDate.of(2000, 12, 1), Gender.FEMALE).mandator().buildAndSave();
		mandator = coreModelService.load(_mandator.getId(), IMandator.class).get();
		
		user = new IUserBuilder(coreModelService, "user_ctx", _mandator).buildAndSave();
	}
	
	@Override
	public Optional<IUser> getActiveUser(){
		return Optional.of(user);
	}
	
	@Override
	public void setActiveUser(IUser user){
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public Optional<IContact> getActiveUserContact(){
		return Optional.empty();
	}
	
	@Override
	public void setActiveUserContact(IContact user){
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public Optional<IPatient> getActivePatient(){
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public void setActivePatient(IPatient patient){
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public Optional<IMandator> getActiveMandator(){
		return Optional.of(mandator);
	}
	
	@Override
	public void setActiveMandator(IMandator mandator){
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public <T> Optional<T> getTyped(Class<T> clazz){
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public void setTyped(Object object){
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void removeTyped(Class<?> clazz){
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public Optional<?> getNamed(String name){
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public void setNamed(String name, Object object){
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public String getStationIdentifier(){
		// TODO Auto-generated method stub
		return null;
	}
	
}

@@ -565,87 +565,151 @@
 e IM
-odelService coreModelService;%0A%09%0A%09private IMandator mandator;%0A%09private IUser use
+andator mandator;%0A%09%0A%09private IUser testUser;%0A%09%0A%09private IUser activeUser;%0A%09private IContact activeUserContact;%0A%09private IMandator activeMandato
 r;%0A%09
@@ -766,55 +766,8 @@
 e)%7B%0A
-%09%09this.coreModelService = coreModelService;%0A%09%09%0A
 %09%09IP
@@ -1014,12 +1014,81 @@
 ;%0A%09%09
-%0A%09%09u
+setActiveUserContact(mandator);%0A%09%09setActiveMandator(mandator);%0A%09%09%0A%09%09testU
 ser 
@@ -1159,24 +1159,51 @@
 dAndSave();%0A
+%09%09setActiveUser(testUser);%0A
 %09%7D%0A%09%0A%09@Overr
@@ -1271,10 +1271,24 @@
 l.of
-(u
+Nullable(activeU
 ser)
@@ -1351,45 +1351,26 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+activeUser = user;
 %0A%09%7D%0A
@@ -1455,14 +1455,36 @@
 nal.
-empty(
+ofNullable(activeUserContact
 );%0A%09
@@ -1554,45 +1554,33 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+activeUserContact = user;
 %0A%09%7D%0A
@@ -1881,18 +1881,32 @@
 ional.of
-(m
+Nullable(activeM
 andator)
@@ -1981,45 +1981,34 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09
+activeMandator = mandator;
 %0A%09%7D%0A

Enhance TestContextService