package models

import (
	"bwallet/pkg/setting"
	"github.com/jinzhu/gorm"
)

type ApiModule struct {
	Model

	Path     string `json:"path,omitempty"`
	Method   string `json:"method,omitempty"`
	Module   string `json:"module"`
	ParentId int    `json:"parent_id,omitempty"`

	Child []*ApiModule `json:"child,omitempty"`
}

func (a ApiModule) TableName() string {
	return setting.DatabaseSetting.Name_Manage + ".gli_api_module"
}

func GetModules(maps interface{}) ([]*ApiModule, error) {
	var modules []*ApiModule
	err := db.Where(maps).Find(&modules).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return nil, err
	}

	return modules, nil
}
