<?php

/**
 * This file defines the option class
 *
 * @package CGProductBuilder
 * @category Products
 * @author  calguy1000 <calguy1000@cmsmadesimple.org>
 * @copyright Copyright 2010 by Robert Campbell
 */

namespace CGProductBuilder;

/**
 * Define a single option.
 * Options are stored within an option set object.
 *
 * @package CGProductBuilder
 * @property string $name The option name
 * @property string $description The option description (may contain HTML)
 * @property float retailprice The retail price for this option.
 * @property float wholesaleprice The wholesale price for this option.
 */
class option
{
    /**
     * @ignore
     */
    private $_data = array('name'=>null,'description'=>null,'wholesaleprice'=>null,'retailprice'=>null);

    /**
     * @ignore
     */
    public function __get($key)
    {
        switch( $key ) {
        case 'name':
        case 'description':
        case 'retailprice':
        case 'wholesaleprice':
            return $this->_data[$key];

        default:
            throw new \CmsInvalidDataException($key.' is not a valid member of '.__CLASS__);
        }
    }

    /**
     * @ignore
     */
    public function __set($key,$value)
    {
        switch( $key ) {
        case 'name':
        case 'description':
            $this->_data[$key] = trim((string) $value);
            break;

        case 'retailprice':
        case 'wholesaleprice':
            $this->_data[$key] = (float) $value;
            break;

        default:
            throw new \CmsInvalidDataException($key.' is not a valid member of '.__CLASS__);
        }
    }

    /**
     * @ignore
     */
    public function __isset($key)
    {
        switch( $key ) {
        case 'name':
        case 'description':
        case 'retailprice':
        case 'wholesaleprice':
            return isset($this->_data[$key]);

        default:
            throw new \CmsInvalidDataException($key.' is not a valid member of '.__CLASS__);
        }
    }

    /**
     * @ignore
     */
    public function __unset($key)
    {
        switch( $key ) {
        case 'name':
        case 'description':
        case 'retailprice':
        case 'wholesaleprice':
            $this->_data[$key] = null;

        default:
            throw new \CmsInvalidDataException($key.' is not a valid member of '.__CLASS__);
        }
    }

} // end of class
?>
