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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.security.acls.model.MutableAclService;
import org.springframework.stereotype.Service;

import com.iqser.red.service.persistence.management.v1.processor.acl.RedPermission;
import com.iqser.red.service.persistence.management.v1.processor.acl.custom.api.ICustomPermissionService;
import com.iqser.red.service.persistence.management.v1.processor.client.tenantusermanagementservice.UsersClient;
import com.iqser.red.service.persistence.management.v1.processor.service.DossierManagementService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.Dossier;

@Service
public class ViewObjectDossierObjectPermissionService extends ICustomPermissionService<Dossier, String> {

    private final DossierManagementService dossierManagementService;


    public ViewObjectDossierObjectPermissionService(UsersClient usersClient, MutableAclService mutableAclService, DossierManagementService dossierManagementService) {

        super(usersClient, mutableAclService);
        this.dossierManagementService = dossierManagementService;
    }


    @Override
    public String getIdentifier() {

        return "Dossier";
    }


    @Override
    protected Collection<String> provideAllObjectIds() {

        return dossierManagementService.getAllDossiers(true, true).stream().map(Dossier::getId).collect(Collectors.toList());
    }


    @Override
    public Set<RedPermission> definingPermissions() {

        return Set.of(RedPermission.APPROVE, RedPermission.REVIEW, RedPermission.OWNER);
    }


    @Override
    public RedPermission forPermission() {

        return RedPermission.VIEW_OBJECT;
    }

}
