package ii

import (
	"testing"

	"golib/v2/features/mo"
)

type testUser mo.M

func (u testUser) Name() string                    { return "" }
func (u testUser) UserName() string                { return "" }
func (u testUser) Flag() bool                      { return true }
func (u testUser) IsSysadmin() bool                { return false }
func (u testUser) Company() mo.ObjectID            { return mo.NilObjectID }
func (u testUser) CompanyALL() mo.A                { return mo.A{} }
func (u testUser) Group(_ string) bool             { return false }
func (u testUser) Role(_ string) (string, bool)    { return "", false }
func (u testUser) Perms(_ string) ([]string, bool) { return []string{}, false }

func (u testUser) ID() mo.ObjectID {
	return mo.ID.New()
}
func (u testUser) Get(k string) any {
	v, ok := u[k]
	if !ok {
		return nil
	}
	return v
}

func TestLoadPerms(t *testing.T) {
	permission, err := LoadPerms("./_test/filter.json")
	if err != nil {
		t.Error(err)
		return
	}
	data := mo.M{
		"department": "department_test",
	}
	d, ok := permission.Has("test.user", testUser(data))
	if !ok {
		t.Error()
		return
	}
	t.Log(d)
}
