package resource

import "testing"

func TestApplyGrantOperatorsUsesSourceSpecificProfiles(t *testing.T) {
	grants := []grantDTO{
		{GrantID: "grant-admin", GrantSource: "admin", OperatorUserID: 7},
		{GrantID: "grant-manager", GrantSource: "manager_center", OperatorUserID: 9001},
	}

	applyGrantOperators(grants, map[uint]adminOperator{
		7: {UserID: 7, Username: "admin", Name: "后台管理员"},
	}, map[int64]managerOperator{
		9001: {UserID: 9001, DisplayUserID: "10086", Username: "经理 A", Avatar: "https://cdn.example/avatar.png"},
	})

	if grants[0].Operator == nil || grants[0].Operator.Source != "admin" || grants[0].Operator.Name != "后台管理员" || grants[0].Operator.Username != "admin" {
		t.Fatalf("admin operator mismatch: %+v", grants[0].Operator)
	}
	if grants[1].Operator == nil || grants[1].Operator.Source != "manager_center" || grants[1].Operator.DisplayUserID != "10086" || grants[1].Operator.Avatar == "" || grants[1].Operator.Username != "经理 A" {
		t.Fatalf("manager operator mismatch: %+v", grants[1].Operator)
	}
}
