/**
 * Вспомогательный класс - расчёт цены
 *
 * @property string garbage
 *           тип мусора
 * @property float container
 *           тип контейнера (объём)
 * @property int count
 *           количество контейнеров
 * @property bool loading
 *           с погрузкой или без
 * @property внутри ТТК или нет
				0 - не внутри
				1 - ЦАО
				2 - Сад. кольцо - ТТК
 *           
 * @property int price
 *           итоговая цена
 * @property int per
 *           цена одного контейнера
 */
CalcClass.PriceClass = go.Class({
    
    'TABLES' : [    
        {
            container : "0.8", 
            garbage   : ["household", "debris"], 
            prices    : [
                [1, 450],
                [11, 350],
                [31, 300],
                [71, 270],
                [250, 230]
            ]
        },
        {
            container : "1.1",
            garbage   : ["household", "debris"],
            prices    : [
                [1, 495],
                [11, 385],
                [31, 330],
                [71, 295],
                [250, 255]
            ]
        },
		{
            container : "8",
            garbage   : ["debris", "bulky", "household", "snow"],
            inttk     : 1,
            prices    : [
                [1, 4200],
                [6, 4000],
                [11, 3800],
                [31, 3700]
            ]
        },
		{
            container : "8",
            garbage   : ["debris", "bulky", "household", "snow"],
            inttk     : 2,
            prices    : [
                [1, 4000],
                [6, 3800],
                [11, 3700],
                [31, 3600]
            ]
        },
		{
            container : "8",
            garbage   : ["debris", "bulky", "household", "snow"],
            inttk     : 0,
            prices    : [
                [1, 3700],
                [16, 3500],
                [31, 3400]
            ]
        },
		
		/*
        {
            container : "8",
            garbage   : ["debris", "bulky"],
            inttk     : true,
            prices    : [
                [1, 4200],
                [6, 3800],
                [11, 3500],
                [31, 3200]
            ]
        },
        {
            container : "8",
            garbage   : ["household"],
            inttk     : true,
            prices    : [
                [1, 4000],
                [6, 3600],
                [11, 3300],
                [31, 3000]
            ]
        },
        {
            container : "8",
            garbage   : ["debris", "bulky"],
            inttk     : false,
            prices    : [
                [1, 3700],
                [6, 3400],
                [11, 3200],
                [31, 3000]
            ]
        },
        {
            container : "8",
            garbage   : ["household"],
            inttk     : false,
            prices    : [
                [1, 3500],
                [6, 3200],
                [11, 3000],
                [31, 2800]                
            ]
        },
        {
            container : "8",
            garbage   : ["snow"],
            prices    : [
                [1, 3000]
            ]
        },
		*/
		
			
		{
            container : "20",
            garbage   : ["debris", "bulky", "household", "snow"],
            inttk     : 1,
            prices    : [
                [1, 8000],
                [11, 7500],
                [26, 7300],
                [51, 7000]
            ]
        },
		{
            container : "20",
            garbage   : ["debris", "bulky", "household", "snow"],
            inttk     : 0,
            prices    : [
                [1, 7500],
                [11, 7300],
                [26, 7000]
            ]
        },
		{
            container : "20",
            garbage   : ["debris", "bulky", "household", "snow"],
            inttk     : 2,
            prices    : [
                [1, 7500],
                [11, 7300],
                [26, 7000]
            ]
        },
		
		
		
		
	/*	
        {
            container : "20",
            garbage   : ["debris", "bulky"],
            inttk     : true,
            prices    : [
                [1, 8000],
                [6, 7500],
                [11, 7200],
                [31, 6800]
            ]
        },
        {
            container : "20",
            garbage   : ["household"],
            inttk     : true,
            prices    : [
                [1, 7800],
                [6, 7300],
                [11, 7000],
                [31, 6600]
            ]
        },
        {
            container : "20",
            garbage   : ["debris", "bulky"],
            inttk     : false,
            prices    : [
                [1, 7500],
                [6, 7200],
                [11, 6900],
                [31, 6700]
            ]
        },
        {
            container : "20",
            garbage   : ["household"],
            inttk     : false,
            prices    : [
                [1, 7300],
                [6, 7000],
                [11, 6700],
                [31, 6500]
            ]
        },
        {
            container : "20",
            garbage   : ["snow"],
            prices    : [
                [1, 5800]
            ]
        },
	*/

		{
            container : "27",
            garbage   : ["debris", "bulky", "household"],
            inttk     : 1,
            prices    : [
                [1, 8500],
                [11, 8000],
                [26, 7500]
            ]
        },
		{
            container : "27",
            garbage   : ["debris", "bulky", "household"],
            inttk     : 0,
            prices    : [
                [1, 8000],
                [11, 7700],
                [26, 7500]
            ]
        },
		{
            container : "27",
            garbage   : ["debris", "bulky", "household"],
            inttk     : 2,
            prices    : [
                [1, 8000],
                [11, 7700],
                [26, 7500]
            ]
        },


	/*
        {
            container : "27",
            garbage   : ["debris", "bulky"],
            inttk     : true,
            prices    : [
                [1, 8500],
                [6, 8000],
                [11, 7700],
                [31, 7200]
            ]
        },
        {
            container : "27",
            garbage   : ["household"],
            inttk     : true,
            prices    : [
                [1, 8300],
                [6, 7800],
                [11, 7500],
                [31, 7000]
            ]
        },
        {
            container : "27",
            garbage   : ["debris", "bulky"],
            inttk     : false,
            prices    : [
                [1, 8000],
                [6, 7700],
                [11, 7400],
                [31, 7000]
            ]
        },
        {
            container : "27",
            garbage   : ["household"],
            inttk     : false,
            prices    : [
                [1, 7800],
                [6, 7500],
                [11, 7200],
                [31, 6800]
            ]
        },
	*/
	
		{
            container : "33",
            garbage   : ["debris", "bulky", "household"],
            prices    : [
                [1, 9300],
                [11, 9000],
                [26, 8500]
            ]
        },

	/*
        {
            container : "33",
            garbage   : ["debris", "bulky"],
            inttk     : true,
            prices    : [
                [1, 9500],
                [6, 8700],
                [11, 8200],
                [31, 7700]
            ]
        },
        {
            container : "33",
            garbage   : ["household"],
            inttk     : true,
            prices    : [
                [1, 9300],
                [6, 8500],
                [11, 8000],
                [31, 7500]
            ]
        },
        {
            container : "33",
            garbage   : ["debris", "bulky"],
            inttk     : false,
            prices    : [
                [1, 9000],
                [6, 8500],
                [11, 8200],
                [31, 7800]
            ]
        },
        {
            container : "33",
            garbage   : ["household"],
            inttk     : false,
            prices    : [
                [1, 8800],
                [6, 8300],
                [11, 8000],
                [31, 7600]
            ]
        } 
	*/	
    ],
    
    'PRICE_LOADING': 600,
    
    /**
     * Конструктор
     *
     * @param string garbage
     * @param float container
     * @param int count
     * @param bool loading
     * @param bool inttk
     */
    '__construct': (function(garbage, container, count, loading, inttk) {
        this.garbage   = garbage;
        this.container = container;
        this.count     = count;
        this.loading   = loading;
        this.inttk     = inttk;
    }),
    
    /**
     * Произвести вычисления
     */
    'calc': (function() {
        var prices = this.getPricesTable();
        this.per   = this.calcPer(prices);
        if (this.loading) {
            this.per += this.PRICE_LOADING;
        }
        this.price = this.per * this.count;
    }),
    
    'getPricesTable': (function() {
        var tables = this.TABLES;
        var len    = tables.length;
        for (var i = 0; i < len; i++) {
            var table = tables[i];
            if (this.curTable(table)) {
                return table.prices;
            }
        }
        throw new "prices table";
    }),
    
    'curTable': (function(table) {
        if (table.container != this.container) {
            return false;
        }
        if (typeof(table.inttk) != "undefined") {
            if (table.inttk != this.inttk) {
                return false;
            }
        }
        var current = this.garbage;        
        var garbage = table.garbage;
        var len     = garbage.length;
        for (var i = 0; i < len; i++) {
            if (garbage[i] == current) {
                return true;
            }
        }
        return false;
    }),
    
    'calcPer': (function(prices) {
        var count = this.count;
        var len = prices.length;
        var per = 0;
        for (var i = 0; i < len; i++) {
            var el = prices[i];
            var min   = el[0];
            var price = el[1];
            if (count == min) {
                return price;
            }
            if (count < min) {
                return per;
            }
            per = price;
        }
        return per;
    }),
    
    'eoc': null
});

