class RainwaterCollector extends Building
{
    constructor( engine , x , z )
    {
        super( engine , x , z , BuildingType.WATER );

        game.waterProduction += 2;
        game.waterStorage += 20;
        this.waterProduction = 2;
        this.waterStorage = 20;
        ui.updateGameUI();

        this.level = 0;
        this.maxLevel = 2;

        this.model = Sparrow.ModelLoader.loadGLTF( engine , "models/water_collector.gltf" );
        this.model.setTranslation( this.x , 0 , this.z );
        this.model.addOnClickHandler( () => {
            game.buildingManager.buildingClicked( this );
        } );
        water.addObject( this.model );
        shadowMap.addObject( this.model );

        this.waterSurfaceModel = Sparrow.ModelLoader.loadGLTF( engine , "models/water_collector_water.gltf" );
        this.waterSurfaceModel.setTranslation( this.x , game.waterFillLevel , this.z );
    }

    demolish()
    {
        game.waterProduction -= this.waterProduction;
        game.waterStorage -= this.waterStorage;
        game.waterChanged();
    }

    upgrade()
    {
        if ( this.level < this.maxLevel )
        {
            if ( this.level === 0 )
            {
                if ( game.money >= Config.WATER_UPGRADE_PRICE_1 )
                {
                    this.level++;
                    this.waterProduction += 3;
                    this.waterStorage += 5;
                    game.waterProduction += 3;
                    game.waterStorage += 5;
                    game.money -= Config.WATER_UPGRADE_PRICE_1;
                    game.waterChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
            else if ( this.level === 1 )
            {
                if ( game.money >= Config.WATER_UPGRADE_PRICE_2 )
                {
                    this.level++;
                    this.waterProduction += 4;
                    this.waterStorage += 10;
                    game.waterProduction += 4;
                    game.waterStorage += 10;
                    game.money -= Config.WATER_UPGRADE_PRICE_2;
                    game.waterChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
        }
    }

    updateWaterFillLevel()
    {
        this.waterSurfaceModel.setTranslation( this.x , game.waterFillLevel , this.z );
    }

    delete()
    {
        super.delete();
        this.waterSurfaceModel.delete();
    }

    draw()
    {
        super.draw();
        this.waterSurfaceModel.draw();
    }
}