package auth

import (
	"context"

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

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

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

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

func (l *UnbindAccountLogic) UnbindAccount(req *types.AuthUnbindReq) (resp *types.OkData, err error) {
	uid, _ := middleware.UIDFrom(l.ctx)
	if err := l.svcCtx.Auth.UnbindAccount(l.ctx, uid, req.LoginId, req.Platform); err != nil {
		return nil, err
	}
	return &types.OkData{Ok: true, Message: "unbound"}, nil
}
