class Farm extends Building
{
    constructor( engine , x , z )
    {
        super( engine , x , z , BuildingType.FARM );

        game.foodProduction += 2;
        game.foodStorage += 10;
        ui.updateGameUI();
        this.foodProduction = 2;
        this.foodStorage = 10;

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

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

    demolish()
    {
        game.foodProduction -= this.foodProduction;
        game.foodStorage -= this.foodStorage;
        game.foodChanged();
    }

    upgrade()
    {
        if ( this.level < this.maxLevel )
        {
            if ( this.level === 0 )
            {
                if ( game.money >= Config.FARM_UPGRADE_PRICE_1 )
                {
                    this.level++;
                    this.foodProduction += 3;
                    this.foodStorage += 5;
                    game.foodProduction += 3;
                    game.foodStorage += 5;
                    game.money -= Config.FARM_UPGRADE_PRICE_1;
                    game.foodChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
            else if ( this.level === 1 )
            {
                if ( game.money >= Config.FARM_UPGRADE_PRICE_2 )
                {
                    this.level++;
                    this.foodProduction += 4;
                    this.foodStorage += 10;
                    game.foodProduction += 4;
                    game.foodStorage += 10;
                    game.money -= Config.FARM_UPGRADE_PRICE_2;
                    game.foodChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
        }
    }
}