package com.p3.bewoplaner.data.repository.specifications;

import com.p3.bewoplaner.data.repository.models.GroupRealm;

import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmQuery;

/**
 * Created by Rares Teodorescu on 10/03/2017.
 */
public class GroupByNameSpecification implements RealmSpecification<GroupRealm> {

    private final String mName;
    private final long mUserId;

    public GroupByNameSpecification(String name, long userId) {
        mName = name;
        mUserId = userId;
    }

    @Override
    public RealmQuery<GroupRealm> toRealmQuery(Realm realm) {
        return realm.where(GroupRealm.class)
                .equalTo(GroupRealm.USER_ID, mUserId)
                .contains(GroupRealm.NAME, mName, Case.INSENSITIVE);
    }
}
