package auth

import (
	"context"

	"haixun-backend/internal/middleware"
	authusecase "haixun-backend/internal/model/auth/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type LogoutLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
	return &LogoutLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *LogoutLogic) Logout(authorization string) (*types.LogoutData, error) {
	err := l.svcCtx.AuthToken.Logout(l.ctx, authusecase.LogoutRequest{
		AccessToken: middleware.BearerToken(authorization),
	})
	if err != nil {
		return nil, err
	}
	return &types.LogoutData{OK: true}, nil
}
