package com.atlassian.bitbucket.permission;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

public abstract class SimpleEffectiveResourcePermissionBase extends SimpleEffectivePermissionBase {

    protected final int id;

    public SimpleEffectiveResourcePermissionBase(int id, Permission permission) {
        super(permission);
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj != null && getClass().equals(obj.getClass())) {
            SimpleEffectiveResourcePermissionBase that = (SimpleEffectiveResourcePermissionBase) obj;

            return Objects.equal(id, that.id) && Objects.equal(permission, that.permission);
        }

        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id, permission);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .addValue(String.format("%s: %d", permission, id))
                .toString();
    }
}
