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

import com.atlassian.bitbucket.repository.Repository;
import net.java.ao.Accessor;
import net.java.ao.OneToMany;
import net.java.ao.Preload;
import net.java.ao.RawEntity;
import net.java.ao.schema.*;

@Table("RESTRICTED_REF")
@Preload
public interface AoRefRestriction extends RawEntity<Integer> {
    String ID_COLUMN = "REF_ID";
    String REPOSITORY_ID_COLUMN = "REPOSITORY_ID";
    String TYPE_COLUMN = "RESTRICTION_TYPE";
    String REF_MATCHER_TYPE_COLUMN = "REF_TYPE";
    String REF_MATCHER_ID_COLUMN = "REF_VALUE";
    int MAX_REF_MATCHER_ID_LENGTH = 255;
    int MAX_REF_MATCHER_TYPE_LENGTH = 255;

    @OneToMany(reverse = "getRestriction")
    AoAccessGrant[] getAccessGrants();

    @AutoIncrement
    @NotNull
    @PrimaryKey(ID_COLUMN)
    Integer getId();

    /**
     * @return the id of the {@link Repository repository} containing the
     * {@link #getMatcherId branch} the permission was granted on.
     */
    @NotNull
    @Accessor(REPOSITORY_ID_COLUMN)
    @Indexed
    Integer getRepositoryId();

    @NotNull
    @Accessor(REF_MATCHER_TYPE_COLUMN)
    @Indexed
    @StringLength(MAX_REF_MATCHER_TYPE_LENGTH)
    String getMatcherType();

    /**
     * @return the value of the restriction. Either the fully qualified branch name or a regular expression
     */
    @NotNull
    @Accessor(REF_MATCHER_ID_COLUMN)
    @Indexed
    @StringLength(MAX_REF_MATCHER_ID_LENGTH)
    String getMatcherId();

    @NotNull
    @Accessor(TYPE_COLUMN)
    String getType();
}
