/** 
 * A class representing a classroom
 */
 
public class ClassRoom {
  
  /** This room's maximum capacity (seating and standing) 
      as per fire regulations/ */
  private int maxCapacity;        

  /** This room's current seating capacity/ */
  private int maxSeating;     

  /** This room's maximum seating capacity. */
  private int currSeating; 

  /** This room's AV equipment object. */
  private AVEquipment avEquip;

  /** The name of this room. */
  private String roomName;

  /** The name of the person assigned to this room. */
  private String ownerName; 

  /** This room's unqiue room number. */
  private int roomNum;                 

  /** Whether this room is a temporary or permanent structure. */
  private boolean permanent;  

  /** The number of rooms created from this class. */
  private static int numRooms = 0;  
  
  
  /** 
   * Constructor with no parameters. default values are:
   * 100 people maximum; 50 current seating; 75 maximum 
   * seating; empty string for its name and no audiovisual
   * capability
   */
   
  public ClassRoom() {
    maxCapacity= 100;
    maxSeating= 75;
    currSeating= 50;
    avEquip= null;
    roomName= "";
    ownerName = "";
    roomNum= ++numRooms;
    permanent= true;
  }
  /**
   * Constructor for the ClassRoom class. 
   * Parameters are the maximum total capacity and the 
   * maximum seating capacity in that order. The current 
   * seating capacity is equal to the maximum seating 
   * capacity. The room's name and its owner's name are 
   * the empty string.
   */
  
  public ClassRoom(int mC, int mS){
    maxCapacity= mC;
    maxSeating= mS;
    currSeating= maxSeating;
    avEquip= null;
    roomName= "";
    ownerName= "";
    roomNum= ++numRooms;
    permanent= true;
  }
  /**
   * Constructor for the ClassRoom class. 
   * Parameters are maximum total capacity,
   * maximum seating capacity, room name and 
   * owner's name in that order
   */
  public ClassRoom(int maxCapacity, int maxSeating, int currSeating, String name, String oName){
    this.maxCapacity= maxCapacity;
    this.maxSeating= maxSeating;
    this.currSeating= currSeating;
    avEquip= null;
    roomName= name;
    ownerName= oName;
    roomNum= ++numRooms;
    permanent= true;
  }
  
  /** 
   * Return this room's maximum capacity as an integer.
   */
  public int getMaxCapacity() {
    return maxCapacity;
  }
  
  /** 
   * Return this room's maximum seating capacity as an integer.
   */
  public int getMaxSeating() {
    return maxSeating;
  }
   
  /** 
   * Return this room's current seating capacity as an integer.
   */
  public int getCurrSeating() {
    return currSeating;
  }
  
  /** 
   * Return this room's current seating capacity for exams as an integer.
   * The exam capacity is defined as the largest integer that 
   * is equal to or less than one half of the current seating capacity. 
   */
  public int getExamSeating() {
    return (currSeating/2);
  }
  
  /** 
   * Return whether this room has any AV equipment as a boolean.
   */
  public boolean hasAVEquipment() {
    return (avEquip != null);
  }
  
  /** 
   * Return this room's name as a String.
   */
  public String getRoomName() {
    return roomName;
  }
  
  /** 
   * Return the name of this room's owner as a String.
   */
  public String getOwnerName() {
    return ownerName;
  }
  
  /** 
   * Return the number of instances of ClassRoom created
   */

  public static int getNumRooms(){
    return numRooms;
  }
  
  /**  
   * Creates an AVEquipment unit and adds it to this room. 
   * If the room already has AVEqipment the old equipment is 
   * replaced by the one created in this method. 
   * (The old one is sent to a charity, perhaps.)
   */
  public void addAVEquipment() { 
    avEquip = new AVEquipment();
  }
  
  /**  
   * Removes this room's AV equipment.
   */
  public void removeAVEquipment() { 
    avEquip= null;
  }
  
  /**  
   * Moves an AVEquipment object from one classroom to another. 
   * The first parameter is the source classroom, the second the target.
   */
  public static void moveAVUnit(ClassRoom fromRoom, ClassRoom toRoom) {
    toRoom.avEquip= fromRoom.avEquip;
    fromRoom.avEquip = null;
  }
  
  /**
   * Sets this room's name to the given name
   */
  public void setRoomName(String name) {
    roomName = name;
  }
  
  /**
   * Sets this room's owner's name to the given name
   */
   public void setOwnerName(String name) {
    ownerName = name;
  }
  
  /** 
   * Increase the current seating capacity by the given number of seats. 
   * If the resulting number of seats would exceed the room's maximum 
   * seating capacity, the number of seats in the room is set to the 
   * maximum seating capacity.
   */
  public void addSeats(int seatsToAdd) {
    currSeating= Math.min((currSeating + seatsToAdd),maxSeating);
  }
  
  /** 
   * Decrease the current seating capacity by the given number of seats. 
   * If the resulting number of seats would be less than 0, the number of 
   * seats in the room is set to 0.
   */
  public void removeSeats(int seatsToRemove) {
    currSeating = Math.max((currSeating - seatsToRemove),0);
  }
  
  /**
   * Return true if this classroom has the same owner as the given 
   * classroom; return false otherwise.
   */
  public boolean hasSameOwner(ClassRoom otherRoom) {
    return otherRoom.ownerName.equals(this.ownerName);
  }
  
  /**
   * Return true if this classroom has the same AV equipment as the given 
   * classroom; return false otherwise.
   */
  public boolean hasSameAVEquipment(ClassRoom otherRoom) {
    return this.avEquip.equals(otherRoom.avEquip);
  }
  
  /**
   * Return true if this classroom is a temporary structure; 
   * return false otherwise. 
   */
  public boolean isPortable() {
    return !permanent;
  }
  
 /**
  * Return true if the given classrooms have the same maximum room 
  * capacity and maximum seating capacity; return false otherwise.
  */
  public static boolean areEquivalent(ClassRoom oneRoom, ClassRoom otherRoom) {
    return ((oneRoom.maxCapacity == otherRoom.maxCapacity) && 
           (oneRoom.maxSeating == otherRoom.maxSeating));
  }
  
  /**
   * Compares this ClassRoom to the given object and return true if they 
   * have the same room number; return false otherwise
   */
  public boolean equals(ClassRoom otherRoom) {
    return (this.roomNum == otherRoom.roomNum);
  }
    
}

