<?php

namespace Kanzu\StoreVoiceAI\Services;

// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class Account_Info
{

    public function get_user_account_details( $user_email ) {
        // Get the email address from the request
        $email = sanitize_email( $user_email );
    
        // Query the user by email address
        $user = get_user_by( 'email', $email );
    
        // If no user is found, return an error message
        if ( ! $user ) {
            return $user;
        }
    
        // Get WooCommerce-specific user data (billing, shipping, etc.)
        $user_data = array(
            'user_id'   => $user->ID,
            'first_name'=> $user->first_name,
            'last_name' => $user->last_name,
            'email'     => $user->user_email,
            'phone'     => get_user_meta( $user->ID, 'billing_phone', true ),
            'billing_address' => array(
                'address_1' => get_user_meta( $user->ID, 'billing_address_1', true ),
                'address_2' => get_user_meta( $user->ID, 'billing_address_2', true ),
                'city'      => get_user_meta( $user->ID, 'billing_city', true ),
                'postcode'  => get_user_meta( $user->ID, 'billing_postcode', true ),
                'country'   => get_user_meta( $user->ID, 'billing_country', true ),
                'state'     => get_user_meta( $user->ID, 'billing_state', true ),
            ),
            'shipping_address' => array(
                'address_1' => get_user_meta( $user->ID, 'shipping_address_1', true ),
                'address_2' => get_user_meta( $user->ID, 'shipping_address_2', true ),
                'city'      => get_user_meta( $user->ID, 'shipping_city', true ),
                'postcode'  => get_user_meta( $user->ID, 'shipping_postcode', true ),
                'country'   => get_user_meta( $user->ID, 'shipping_country', true ),
                'state'     => get_user_meta( $user->ID, 'shipping_state', true ),
            ),
        );
    
        // Return the user account details
        return $user_data;
    }

}