<?php

namespace FCA\StockApi\Document\Offer;

use FCA\StockApi\Document\Base;

class Version extends Base
{
    /**
     * @var string
     */
    protected $code;

    /**
     * @var string
     */
    protected $commercialCode;

    /**
     * @var string
     */
    protected $name;

    /**
     * @var array
     */
    protected $slug;

    /**
     * @var float
     */
    protected $price;

    /**
     * Version constructor.
     * @param $version
     * @throws \FCA\StockApi\Exception\ApiException
     */
    public function __construct($version)
    {
        $requiredKeys = ['code', 'commercial_code', 'name', 'slug', 'price'];
        $this->checkKeys($requiredKeys, $version);

        $this->code = $version['code'];
        $this->commercialCode = $version['commercial_code'];
        $this->name = $version['name'];
        $this->slug = $version['slug'];
        $this->price = $version['price'];
    }

    /**
     * @return string
     */
    public function getCode()
    {
        return $this->code;
    }

    /**
     * @return string
     */
    public function getCommercialCode()
    {
        return $this->commercialCode;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return array
     */
    public function getSlug()
    {
        return $this->slug;
    }

    /**
     * @return float
     */
    public function getPrice()
    {
        return $this->price;
    }

    public function toArray()
    {
        return [
            'code' => $this->getCode(),
            'commercialCode' => $this->getCommercialCode(),
            'name' => $this->getName(),
            'slug' => $this->getSlug(),
            'price' => $this->getPrice()
        ];
    }
}
