package ch.unisg.executorpool.adapter.out.persistence.mongodb;

import java.net.URI;
import java.net.URISyntaxException;

import org.springframework.stereotype.Component;

import ch.unisg.executorpool.domain.ExecutorClass;

@Component
public class ExecutorMapper {
    
    ExecutorClass mapToDomainEntity(MongoExecutorDocument executorClass) {
        try {
            return new ExecutorClass(
                new ExecutorClass.ExecutorUri(new URI(executorClass.executorUri)),
                new ExecutorClass.ExecutorTaskType(executorClass.executorTaskType)
            );
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
    }

    MongoExecutorDocument mapToMongoDocument(ExecutorClass executorClass) {
        return new MongoExecutorDocument(executorClass.getExecutorUri().getValue().toString(),
            executorClass.getExecutorTaskType().getValue()
        );
    }
}
