package main

import "sparrow/pkg/models"

func (r *Registry) FindRuleChains(vendorId string, reply *[]*models.RuleChain) error {
	db, err := getDB()
	if err != nil {
		return err
	}
	return db.Where("vendor_id = ?", vendorId).
		Find(reply).Error
}

func (r *Registry) FindRuleChainById(ruleChainId string, reply *models.RuleChain) error {
	db, err := getDB()
	if err != nil {
		return err
	}
	return db.Where("record_id = ?", ruleChainId).
		First(reply).Error
}

func (r *Registry) FindRuleNodeById(nodeId string, reply *models.RuleNode) error {
	db, err := getDB()
	if err != nil {
		return err
	}
	return db.Where("record_id = ?", nodeId).First(reply).Error
}

func (r *Registry) FindRuleChainNodes(ruleChainId string, reply *[]*models.RuleNode) error {
	db, err := getDB()
	if err != nil {
		return err
	}
	return db.Where("rule_chain_id = ?", ruleChainId).
		Find(reply).Error
}

func (r *Registry) GetRuleNodeRelations(nodeId string, reply*[]*models.Relation) error {
	db, err := getDB()
	if err != nil {
		return err
	}
	return db.Where("from_id = ?", nodeId).Find(reply).Error
}

