package auth

import (
	"context"

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

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

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

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

func (l *BindAccountLogic) BindAccount(req *types.AuthBindReq) (resp *types.IdentityPublic, err error) {
	uid, _ := middleware.UIDFrom(l.ctx)
	id, err := l.svcCtx.Auth.BindAccount(l.ctx, uid, req.LoginId, req.Platform, req.AccountType, req.Password)
	if err != nil {
		return nil, err
	}
	out := types.IdentityFromModel(id)
	return &out, nil
}
