<commit_before><?php
/**
 * Class PilipayGood
 *
 * - required fields:
 * @property $name          string
 * @property $pictureUrl    string
 * @property $price         number       in order.currencyType
 * @property $productUrl    string
 * @property $productId     string
 * @property $quantity      int
 * @property $weight        number
 * @property $weightUnit    string       g/kg/lb/oz
 *
 * - optional fields:
 * @property $attr          string      the good's attributes, like: color, size...
 * @property $category      string      the good's category when taxing
 * @property $height        string      ?? and unit??
 * @property $length        string      ?? and unit??
 * @property $width         string      ?? and unit??
 */
class PilipayGood extends PilipayModel
{
    /**
     * 转换为API中的那种array表示形式
     * @return array
     */
    public function toApiArray(){
        parent::verifyFields();

        return array_map('strval', array(
            // required:
            'name' => $this->name,
            'pictureURL' => $this->pictureUrl,
            'price' => intval($this->price * 100), // API: need a price in cent (in order.currencyType)
            'productURL' => $this->productUrl,
            'productId' => $this->productId,
            'quantity' => intval($this->quantity),
            'weight' => intval(self::convertWeightToGram($this->weight, $this->weightUnit)),

            // optional:
            'attr' => $this->attr,
            'category' => $this->category,
            'height' => $this->height,
            'length' => $this->length,
            'width' => $this->width,
        ));
    }

    /**
     * 将重量转换为以克为单位的数值
     * @param $amount
     * @param $unit<commit_msg>add default url for product picture<commit_after><?php
/**
 * Class PilipayGood
 *
 * - required fields:
 * @property $name          string
 * @property $pictureUrl    string
 * @property $price         number       in order.currencyType
 * @property $productUrl    string
 * @property $productId     string
 * @property $quantity      int
 * @property $weight        number
 * @property $weightUnit    string       g/kg/lb/oz
 *
 * - optional fields:
 * @property $attr          string      the good's attributes, like: color, size...
 * @property $category      string      the good's category when taxing
 * @property $height        string      ?? and unit??
 * @property $length        string      ?? and unit??
 * @property $width         string      ?? and unit??
 */
class PilipayGood extends PilipayModel
{
    const DEFAULT_PICTURE_URL = 'https://api.pilibaba.com/static/img/default-product.jpg';

    /**
     * 转换为API中的那种array表示形式
     * @return array
     */
    public function toApiArray(){
        parent::verifyFields();

        return array_map('strval', array(
            // required:
            'name' => $this->name,
            'pictureURL' => $this->pictureUrl ? $this->pictureUrl : self::DEFAULT_PICTURE_URL,
            'price' => intval($this->price * 100), // API: need a price in cent (in order.currencyType)
            'productURL' => $this->productUrl,
            'productId' => $this->productId,
            'quantity' => intval($this->quantity),
            'weight' => intval(self::convertWeightToGram($this->weight, $this->weightUnit)),

            // optional:
            'attr' => $this->attr,
            'category' => $this->category,
            'height' => $this->height,
            'length' => $this->length,
            'width' => $this->width,
        ));
    }

    /**
     * 将重量转换为以克为单位的数值
     * @param $amount
     * @param $unit
{'fraction_non_alphanumeric': 0.13948973932334996, 'fraction_numerical': 0.0016638935108153079, 'mean_word_length': 2.0285474391267844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3548214', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1043, 'n_words': 251}