class House extends Building
{
    constructor( engine , x , z )
    {
        super( engine , x , z , BuildingType.HOUSE );

        game.beds += 5;
        game.populationChanged();
        this.beds = 5;
        this.level = 0;
        this.maxLevel = 3;

        this.model = Sparrow.ModelLoader.loadGLTF( engine , "models/tent.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.beds -= this.beds;
        game.populationChanged();
    }

    upgrade()
    {
        if ( this.level < this.maxLevel )
        {
            if ( this.level === 0 )
            {
                // house
                if ( game.money >= Config.HOUSE_UPGRADE_PRICE_1 )
                {
                    this.level = 1;
                    this.beds += 5;
                    game.beds += 5;
                    super.delete();
                    this.model = Sparrow.ModelLoader.loadGLTF( engine , "models/police.gltf" );
                    this.model.setTranslation( this.x , 0 , this.z );
                    this.model.addOnClickHandler( () => {
                        game.buildingManager.buildingClicked( this );
                    } );
                    water.addObject( this.model );
                    shadowMap.addObject( this.model );
                    game.money -= Config.HOUSE_UPGRADE_PRICE_1;
                    game.populationChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
            else if ( this.level === 1 )
            {
                // appartment
                if ( game.money >= Config.HOUSE_UPGRADE_PRICE_2 )
                {
                    this.level = 2;
                    this.beds += 10;
                    game.beds += 10;
                    super.delete();
                    this.model = Sparrow.ModelLoader.loadGLTF( engine , "models/apartment.gltf" );
                    this.model.setTranslation( this.x , 0 , this.z );
                    this.model.addOnClickHandler( () => {
                        game.buildingManager.buildingClicked( this );
                    } );
                    water.addObject( this.model );
                    shadowMap.addObject( this.model );
                    game.money -= Config.HOUSE_UPGRADE_PRICE_2;
                    game.populationChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
            else if ( this.level === 2 )
            {
                // highrise
                if ( game.money >= Config.HOUSE_UPGRADE_PRICE_3 )
                {
                    this.level = 3;
                    this.beds += 20;
                    game.beds += 20;
                    super.delete();
                    this.model = Sparrow.ModelLoader.loadGLTF( engine , "models/highrise.gltf" );
                    this.model.setTranslation( this.x , 0 , this.z );
                    this.model.addOnClickHandler( () => {
                        game.buildingManager.buildingClicked( this );
                    } );
                    water.addObject( this.model );
                    shadowMap.addObject( this.model );
                    game.money -= Config.HOUSE_UPGRADE_PRICE_3;
                    game.populationChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
        }
    }
}