package com.atlassian.stash.internal.repository.ref.restriction;

import com.atlassian.bitbucket.repository.ref.restriction.AccessGrant;
import com.atlassian.bitbucket.repository.ref.restriction.RefMatcher;
import com.atlassian.bitbucket.repository.ref.restriction.RefRestriction;
import com.atlassian.bitbucket.repository.ref.restriction.RefRestrictionType;
import com.google.common.collect.ImmutableList;

import javax.annotation.Nonnull;
import java.util.List;

public class SimpleRefRestriction implements RefRestriction {

    private final List<AccessGrant> accessGrants;
    private final int id;
    private final int repositoryId;
    private final RefMatcher target;
    private final RefRestrictionType type;

    public SimpleRefRestriction(int id, int repositoryId, RefMatcher target, RefRestrictionType type, Iterable<AccessGrant> accessGrants) {
        this.accessGrants = ImmutableList.copyOf(accessGrants);
        this.id = id;
        this.repositoryId = repositoryId;
        this.target = target;
        this.type = type;
    }

    @Override
    public List<AccessGrant> getAccessGrants() {
        return accessGrants;
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public int getRepositoryId() {
        return repositoryId;
    }

    @Nonnull
    @Override
    public RefMatcher getMatcher() {
        return target;
    }

    @Nonnull
    @Override
    public RefRestrictionType getType() {
        return type;
    }
}
