class Police extends Building
{
    constructor( engine , x , z )
    {
        super( engine , x , z , BuildingType.POLICE );

        game.policeLevel += 4;
        this.policeLevel = 4;

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

        this.model = Sparrow.ModelLoader.loadGLTF( engine , "models/police_new.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.policeLevel -= this.policeLevel;
    }

    upgrade()
    {
        if ( this.level < this.maxLevel )
        {
            if ( this.level === 0 )
            {
                if ( game.money >= Config.POLICE_UPGRADE_PRICE_1 )
                {
                    this.level++;
                    this.policeLevel += 4;
                    game.policeLevel += 4;
                    game.money -= Config.POLICE_UPGRADE_PRICE_1;
                    game.policeChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
            else if ( this.level === 1 )
            {
                if ( game.money >= Config.POLICE_UPGRADE_PRICE_2 )
                {
                    this.level++;
                    this.policeLevel += 5;
                    game.policeLevel += 5;
                    game.money -= Config.POLICE_UPGRADE_PRICE_2;
                    game.policeChanged();
                    sound_upgrade.play();
                    return;
                }
                else
                {
                    ui.showPopup( "Not enough money." );
                }
            }
        }
    }
}