//go:build e2e

package client

import "context"

// Register creates a user account and returns an authenticated session.
func (c *Client) Register(ctx context.Context, name, email, password string) (AuthSession, int, []byte, error) {
	req := map[string]string{
		"name":     name,
		"email":    email,
		"password": password,
	}
	var out AuthSession
	status, raw, err := c.DoJSON(ctx, "POST", "/api/v1/auth/register", req, &out)
	return out, status, raw, err
}

// RequestMobileVerification starts SMS verification for the authenticated user.
func (c *Client) RequestMobileVerification(ctx context.Context, mobile string) (int, []byte, error) {
	req := map[string]string{"mobile": mobile}
	return c.DoJSON(ctx, "POST", "/api/v1/auth/mobile/request-verification", req, nil)
}

// VerifyMobile completes SMS verification for the authenticated user.
func (c *Client) VerifyMobile(ctx context.Context, code string) (int, []byte, error) {
	req := map[string]string{"code": code}
	return c.DoJSON(ctx, "POST", "/api/v1/auth/mobile/verify", req, nil)
}

// GetMe returns the authenticated user profile.
func (c *Client) GetMe(ctx context.Context) (User, int, []byte, error) {
	var out User
	status, raw, err := c.DoJSON(ctx, "GET", "/api/v1/me", nil, &out)
	return out, status, raw, err
}

// AcceptPendingWorkspaceInvite accepts a mobile-bound workspace invite.
func (c *Client) AcceptPendingWorkspaceInvite(ctx context.Context, inviteID string) (map[string]any, int, []byte, error) {
	var out map[string]any
	status, raw, err := c.DoJSON(ctx, "POST", "/api/v1/auth/pending-invites/"+inviteID+"/accept", nil, &out)
	return out, status, raw, err
}
