package com.iqser.red.service.persistence.management.v1.processor.acl;

import org.springframework.security.acls.domain.ObjectIdentityImpl;
import org.springframework.security.acls.model.ObjectIdentity;
import org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy;

import com.iqser.red.service.persistence.service.v1.api.shared.model.DossierChangeEntry;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.Dossier;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RedObjectIdentityRetrievalStrategy implements ObjectIdentityRetrievalStrategy {

    @Override
    public ObjectIdentity getObjectIdentity(Object domainObject) {

        log.debug("Requesting data for object: {}", domainObject);
        if (domainObject instanceof Dossier) {
            return new ObjectIdentityImpl("Dossier", ((Dossier) domainObject).getId());
        } else if (domainObject instanceof DossierChangeEntry) {
            return new ObjectIdentityImpl("Dossier", ((DossierChangeEntry) domainObject).getDossierId());
        } else if (domainObject instanceof String) {
            // TODO ACL this will not work once we have more than one type.
            return new ObjectIdentityImpl("Dossier", (String) domainObject);
        } else {
            return null;
        }
    }

}
