package workspaces

import (
	"context"
	"fmt"

	"apps/backend/internal/middleware"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RemoveWorkspaceMemberLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRemoveWorkspaceMemberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveWorkspaceMemberLogic {
	return &RemoveWorkspaceMemberLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}

func (l *RemoveWorkspaceMemberLogic) RemoveWorkspaceMember(req *types.RemoveWorkspaceMemberReq) (*types.OkData, error) {
	uid, ok := middleware.UIDFrom(l.ctx)
	if !ok || uid <= 0 {
		return nil, fmt.Errorf("unauthorized")
	}
	if err := l.svcCtx.Growth.RemoveWorkspaceMember(l.ctx, uid, req.Uid, req.Id); err != nil {
		return nil, err
	}
	return &types.OkData{Ok: true}, nil
}
