/**
 *  Copyright © 2025, Luis Andrés Lange <https://javacomm.net>
 *
 *  Previously released under Apache License 2.0; now licensed under MPL 2.0.
 *
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 *  file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 *  ----------------------------------------------------------------------------
 *
 *  Exhibit B - "Incompatible With Secondary Licenses" Notice
 *
 *  This Source Code Form is "Incompatible With Secondary Licenses",
 *  as defined by the Mozilla Public License, v. 2.0.
 *
 *  In short:
 *  - This file may be used, modified, and distributed under MPL 2.0 only.
 *  - It may NOT be relicensed under GPL, LGPL, AGPL, or any other Secondary License.
 *
 *  Rationale:
 *  - Ensures that the code remains MPL-2.0.
 *  - Avoids legal conflicts with GPL-licensed libraries (e.g., VideoLAN).
 *  - Maximizes usability for commercial and security-critical applications.
 *
 */
package net.javacomm.protocol;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Arrays;
import java.util.Objects;



public class CONFERENCE extends MESSAGE {

  public final static String KONFERENZRAUM = "KONFERENZRAUM";
  public final static String AUDIOKEY = "AUDIOKEY";
  public final static String PSEUDOID = "PSEUDOID";
  public final static String OFFHOOK = "OFFHOOK";
  public final static String KONFERENZRAUMUSER = "KONFERENZRAUMUSER";

  private String konferenzraum;
  private String audiokey;
  private String pseudoid;
  private Boolean offhook;
  private KonferenzraumUser[] konferenzraumUser;

  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;
    CONFERENCE other = (CONFERENCE) obj;
    return Objects.equals(konferenzraum, other.konferenzraum)
        && Arrays.equals(konferenzraumUser, other.konferenzraumUser)
        && Objects.equals(audiokey, other.audiokey);
  }



  public String getKonferenzraum() {
    return konferenzraum;
  }



  public KonferenzraumUser[] getKonferenzraumUser() {
    return konferenzraumUser;
  }



  public String getAudiokey() {
    return audiokey;
  }



  /**
   * Wer war der Absender dieser Botschaft?
   * 
   * @return dieser Anwender
   */
  public String getPseudoid() {
    return pseudoid;
  }



  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + Arrays.hashCode(konferenzraumUser);
    result = prime * result + Objects.hash(konferenzraum, audiokey);
    return result;
  }



  /**
   * Den Telefonförer auflegen oder abnehmen.
   * 
   * @return {@code true}, Hörer abnehmen; {@code false} Hörer aufgelegt
   */
  public Boolean isOffhook() {
    return offhook;
  }



  public void setKonferenzraum(String konferenzname) {
    this.konferenzraum = konferenzname;
  }



  public void setKonferenzraumUser(KonferenzraumUser[] konferenzraumUser) {
    this.konferenzraumUser = konferenzraumUser;
  }



  public void setOffhook(Boolean offhook) {
    this.offhook = offhook;
  }



  public void setAudiokey(String conferenceKey) {
    this.audiokey = conferenceKey;
  }



  /**
   * Dieser Anwender sendet die Botschaft {@code CONFERENCE}.
   * 
   * @param userid
   *               dieser Anwender
   */
  public void setPseudoid(String userid) {
    this.pseudoid = userid;
  }



  @Override
  public String toString() {
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.registerTypeAdapter(CONFERENCE.class, new ConferenceSerializer())
        .registerTypeAdapter(KonferenzraumUser.class, new KonferenzraumUserSerializer()).create();
    return gson.toJson(this);
  }
}
