import std.stdio : writeln, readln;

interface Door {
    void open();
    void close();
    bool getState();
}

class MainDoor : Door {
private:
    bool state = false;

public:
    override void open() {
        state = true;
        writeln("Open the door");
    }

    override void close() {
        state = false;
        writeln("Close the door");
    }

    bool getState() {
        return state;
    }
}

class Security : Door {
private:
    Door door;

    bool authenticate() {
        string password;
        if ((password = readln) !is null) {
            return password == "please\n";
        }
        return false;
    }
public:
    this(Door door) {
        this.door = door;
    }

    override void open() {
        if (authenticate()) {
            if (getState()) {
                writeln("The door is already open");
                return;
            }
            this.door.open();
        } else {
            writeln("Incorrect password");
        }
    }

    override void close() {
        if (!getState()) {
            writeln("The door is already close");
            return;
        }
        this.door.close();
    }

    bool getState() {
        return this.door.getState();
    }
}

void playWithDoor(Door door) {
    door.open();
    door.close();
}

void main() {
    Door door = new MainDoor();
    Door pDoor = new Security(door);
    
    playWithDoor(pDoor);
}
