import TVoxSDK from '@telenia/tvox-client-sdk';
import { Component, signal } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatListModule } from '@angular/material/list';
import { TVoxService } from 'src/app/tvox-client-sdk.service';

@Component({
  selector: 'call-channel-status',
  imports: [MatCardModule, MatListModule, MatButtonModule],
  templateUrl: './call-channel-status.component.html',
  standalone: true,
})
export class CallChannelStatus {
  private client!: TVoxSDK.Client;
  protected phoneChannelStatus =
    signal<TVoxSDK.UserStatusMonitor.PhoneStatusValue | null>(null);

  constructor(private tvoxService: TVoxService) {
    this.client = this.tvoxService.getClient(); // recupero il client istanziato in precedenza all'interno del servizio 'TVoxService'
  }

  getPhoneChannelStatus() {
    this.client.user.statusMonitor.start(); // metodo per avviare il monitor dell'utente

    // metodo per sottoscriversi alla variazione dello stato
    this.client.user.statusMonitor.on('phone_status_changed', (data) => {
      this.phoneChannelStatus.set(data.status);
      console.log('phone_status_changed:', data);
    });
  }
}
