package main

import (
	"context"
	"encoding/json"

	"github.com/bogosj/tesla"
)

func noDevice(ctx context.Context, devices []tesla.Device) (d tesla.Device, passcode string, err error) {
	return tesla.Device{}, "", nil
}
func login(ctx context.Context, username string, password string) (string, error) {
	client, err := tesla.NewClient(
		ctx,
		tesla.WithMFAHandler(noDevice),
		tesla.WithCredentials(username, password),
	)
	if err != nil {
		log.LogErrorType(err)
		return "", err
	}

	t, err := client.Token()
	if err != nil {
		log.LogErrorType(err)
		return "", err
	}
	ret, err := json.Marshal(t)
	if err != nil {
		log.LogErrorType(err)
		return "", err
	}
	return string(ret), nil
}
