package models

import (
	"bwallet/pkg/setting"
)

type CasbinRule struct {
	Model

	Ptype string `json:"ptype"`
	V0    string `json:"v0"`
	V1    string `json:"v1"`
	V2    string `json:"v2"`
	V3    string `json:"v3"`
	V4    string `json:"v4"`
	V5    string `json:"v5"`
}

func (c CasbinRule) TableName() string {
	return setting.DatabaseSetting.Name_Manage + ".casbin_rule"
}

func AddRuleRelation(data map[string]interface{}) (error) {
	rule_relation := CasbinRule{
		Ptype: data["ptype"].(string),
		V0:    data["v0"].(string),
		V1:    data["v1"].(string),
		V2:    data["v2"].(string),
		V3:    data["v3"].(string),
		V4:    data["v4"].(string),
		V5:    data["v5"].(string),
	}
	if err := db.Create(&rule_relation).Error; err != nil {
		return err
	}

	return nil
}
