<?php
namespace AICSAPP;

if (!defined('ABSPATH')) exit;

class Helpers {
    public static function site_meta(): array {
        return [
            'url'  => get_site_url(),
            'name' => get_bloginfo('name'),
            'lang' => get_bloginfo('language'),
        ];
    }

    public static function product_payload(\WC_Product $p): array {
        $id = $p->get_id();

        $terms = wp_get_post_terms(
            $id,
            'product_cat',
            ['fields' => 'all']
        );

        $categories = [];
        foreach ($terms as $t) {
            $categories[] = $t->name;
        }

        return [
            'id'    => $id,
            'sku'   => $p->get_sku(),
            'name'  => $p->get_name(),
            'price' => $p->get_price(),
            'url'   => get_permalink($id),

            'categories' => $categories,

            'description' => wp_strip_all_tags(
                $p->get_description() ?: $p->get_short_description()
            ),
        ];
    }
}
