package sresponse

import (
	"net/http"

	"github.com/tech/sendico/pkg/api/http/response"
	"github.com/tech/sendico/pkg/mlogger"
	"github.com/tech/sendico/pkg/model"
)

type loginResponse struct {
	accountResponse
	RefreshToken TokenData `json:"refreshToken"`
}

func Login(logger mlogger.Logger, account *model.Account, accessToken, refreshToken *TokenData) http.HandlerFunc {
	return response.Ok(
		logger,
		&loginResponse{
			accountResponse: accountResponse{
				Account:      *_createAccount(account, false),
				authResponse: authResponse{AccessToken: *accessToken},
			},
			RefreshToken: *refreshToken,
		},
	)
}
