<?php

class gmb_post_factory
{
    public static function create()
    {
        $selection = rand(1, 5);

        switch ($selection)
        {
            case 5:
                return new pep_rally_post();
            case 4:
            case 3:
                return new category_product_post();
            default:
                return new individual_product_post();
        }
    }
}

interface gmb_post_factory_base
{
    public function createPost($data);
}

class individual_product_post implements gmb_post_factory_base
{
    public function createPost($data)
    {
        $action_type = rand(0, 1) == 0 ? "BOOK" : "ORDER";

        return [
            'languageCode' => 'en-US',
            'summary' => $data["rental_description"],
            'callToAction' => [
                'actionType' => $action_type,
                'url' => $data["rental_url"],
            ],
            'media' => [
                'sourceUrl' => $data["rental_image"],
                'mediaFormat' => 'PHOTO',
            ],
            'topicType' => 'STANDARD',
        ];
    }
}

class category_product_post implements gmb_post_factory_base
{
    public function createPost($data)
    {
        $action_type = rand(0, 1) == 0 ? "BOOK" : "ORDER";

        return [
            'languageCode' => 'en-US',
            'summary' => $data["category_description"],
            'callToAction' => [
                'actionType' => $action_type,
                'url' => $data["category_url"],
            ],
            'media' => [
                'sourceUrl' => $data["category_image"],
                'mediaFormat' => 'PHOTO',
            ],
            'topicType' => 'STANDARD',
        ];
    }
}

class pep_rally_post implements gmb_post_factory_base
{
    /**
     * Takes in an array '$data' for passing the homepage URL in
     * @param $data
     * @return array
     */
    public function createPost($data)
    {
        $actions = ["BOOK", "ORDER", "LEARN_MORE"]; // Add your third option here
        $action_type = $actions[array_rand($actions)];

        return [
            'languageCode' => 'en-US',
            'summary' => $data['hype_description'],
            'callToAction' => [
                'actionType' => $action_type,
                'url' => $data["site_url"],
            ],
            'media' => [
                'sourceUrl' => $data['hype_image'],
                'mediaFormat' => 'PHOTO',
            ],
            'topicType' => 'STANDARD',
        ];
    }
}