<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class of sitemap_item
 *
 * @author r.ratsun <r.ratsun@gmail.com>
 */
class sitemap_item
{
    /**
     * @var array
     */
    protected $data = [];

    /**
     * Construct
     *
     * @param string $loc
     * @param string $lastmod
     * @param string $changefreq
     * @param string $priority
     * @param array $images
     */
    public function __construct($loc = '', $lastmod = '', $changefreq = '', $priority = '', $images = [])
    {
        $this->add_loc($loc);
        $this->add_lastmod($lastmod);
        $this->add_changefreq($changefreq);
        $this->add_priority($priority);
        if (!empty($images) && is_array($images)) {
            foreach ($images as $image) {
                $this->add_image($image);
            }
        }
    }

    /**
     * Add location
     * 
     * @param string $loc
     * @return sitemap_item
     */
    public function add_loc($loc)
    {
        $this->data['loc'] = $loc;

        return $this;
    }

    /**
     * Add lastmod
     *
     * @param string $lastmod
     * @return sitemap_item
     */
    public function add_lastmod($lastmod)
    {
        $this->data['lastmod'] = $lastmod;

        return $this;
    }

    /**
     * Add changefreq
     *
     * @param string $changefreq
     * @return sitemap_item
     */
    public function add_changefreq($changefreq)
    {
        $this->data['changefreq'] = $changefreq;

        return $this;
    }

    /**
     * Add priority
     *
     * @param string $priority
     * @return sitemap_item
     */
    public function add_priority($priority)
    {
        $this->data['priority'] = $priority;

        return $this;
    }

    /**
     * Add image
     *
     * @param string $image
     * @return sitemap_item
     */
    public function add_image($image)
    {
        $this->data['images'][] = $image;

        return $this;
    }

    /**
     * Set images
     *
     * @param array $images
     * @return sitemap_item
     */
    public function set_images($images)
    {
        $this->data['images'] = $images;

        return $this;
    }

    /**
     * Get location
     *
     * @return string
     */
    public function get_loc()
    {
        return $this->data['loc'];
    }

    /**
     * Get lastmod
     *
     * @return string
     */
    public function get_lastmod()
    {
        return $this->data['lastmod'];
    }

    /**
     * Get changefreq
     *
     * @return string
     */
    public function get_changefreq()
    {
        return $this->data['changefreq'];
    }

    /**
     * Get priority
     *
     * @return string
     */
    public function get_priority()
    {
        return $this->data['priority'];
    }

    /**
     * Get images
     *
     * @return array
     */
    public function get_images()
    {
        return (!empty($this->data['images'])) ? $this->data['images'] : [];
    }
}
