// Code generated by candi v1.8.18.

package graphqlhandler

import (
	"context"
	"monorepo/services/master-service/internal/modules/acl/domain"

	"pkg.agungdp.dev/candi/tracer"
)

type mutationResolver struct {
	root *GraphQLHandler
}

// AddRole resolver
func (m *mutationResolver) AddRole(ctx context.Context, input struct{ Data domain.AddRoleRequest }) (string, error) {
	trace := tracer.StartTrace(ctx, "AclDeliveryGraphQL:AddRole")
	defer trace.Finish()
	ctx = trace.Context()

	_, err := m.root.uc.SaveRole(trace.Context(), input.Data)
	if err != nil {
		return "", err
	}
	return "Success", nil
}

// GrantUser resolver
func (m *mutationResolver) GrantUser(ctx context.Context, input struct{ Data domain.GrantUserRequest }) (string, error) {
	trace := tracer.StartTrace(ctx, "AclDeliveryGraphQL:GrantUser")
	defer trace.Finish()
	ctx = trace.Context()

	if err := m.root.uc.GrantUser(ctx, input.Data); err != nil {
		return "", err
	}

	return "Success", nil
}

// AddRole resolver
func (m *mutationResolver) RevokeUser(ctx context.Context, input struct{ Data domain.GrantUserRequest }) (string, error) {
	trace := tracer.StartTrace(ctx, "AclDeliveryGraphQL:RevokeUser")
	defer trace.Finish()
	ctx = trace.Context()

	if err := m.root.uc.RevokeUserRole(ctx, input.Data.UserID, input.Data.RoleID); err != nil {
		return "", err
	}
	return "Success", nil
}
