$(function() {
    "use strict";
    if (_.isUndefined(BWA.Chart) || _.isUndefined(BWA.Chart.PointHistoryServiceTypeGet)) {
        throw new Error('need chart.get.helper.js');
        return;
    }

    var PointHistoryServiceTypeGet = BWA.Chart.PointHistoryServiceTypeGet;

    function EnergyServiceGet(siteId) {

        this.base = PointHistoryServiceTypeGet;
        this.base(siteId);
    }

    EnergyServiceGet.prototype = PointHistoryServiceTypeGet.prototype;
    EnergyServiceGet.prototype.constructor = EnergyServiceGet;

    var searchConditions = EnergyServiceGet.SearchConditions = {};

    var CODE = $Code,
        FuelType = CODE.FuelType,
        FT = CODE.FacilityType,
        FC = CODE.FacilityCode,
        F = CODE.Formula;

    searchConditions[FuelType.ELECTRICITY] = {
        FacilityTypeId: FT.ELECTRICITY,
        FacilityCode: FC.ELECTRICITY,
        FormulaId: F[FT.ELECTRICITY].TOTAL_ELECTRICITY_AMOUNT,
    };
    searchConditions[FuelType.GAS] = {
        FacilityTypeId: FT.GAS,
        FacilityCode: FC.GAS,
        FormulaId: F[FT.GAS].TOTAL_GAS_AMOUNT,
    };
    searchConditions[FuelType.WATER] = {
        FacilityTypeId: FT.WATER,
        FacilityCode: FC.WATER,
        FormulaId: F[FT.WATER].TOTAL_WATER_AMOUNT,
    };

    //EnergyServiceGet.prototype.requestGetForUsgaeStatus = function (fuelTypeId, timeIntervalType) {
    EnergyServiceGet.prototype.requestGetForEnergyService = function (fuelTypeId, timeIntervalType, serviceTypeId) {
        var self = this;
        return function(startDate, endDate) {

            var parameters = _.extend(searchConditions[fuelTypeId], {
                TimeIntervalType: timeIntervalType,
                StartDate: startDate,
                EndDate: endDate,
                ServiceTypeId: serviceTypeId
            });

            return self.apiGet(parameters);
        }
    };

    BWA.Chart.EnergyServiceGet = EnergyServiceGet;

});