import { Component, Inject } from '@angular/core';
import { UserRep } from '../../../models/user-management.api.models';
import { UserRepService } from '../../../services/api/user-representation.service';
import { BaseTableComponent } from '../base-table/base-table.component';
import { GuiGridModule, GuiColumn } from '@generic-ui/ngx-grid';
import { ColorModeService } from '../../../services/button/color-mode.service';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { env } from '../../../../environments/environment';

@Component({
  standalone: true,
  imports: [CommonModule, FormsModule, GuiGridModule],
  selector: 'app-user-rep-table',
  templateUrl: '../base-table/base-table.component.html',
  styleUrl: './user-rep-table.component.css'
})
export class UserRepTableComponent extends BaseTableComponent<UserRep, UserRepService> {

  constructor(service: UserRepService, cModeService: ColorModeService) {
    super(service, env.columnNames.userRep, cModeService)
    this.loading = false
  }

  override fetchData(userId?: number, groupId?: number): void {
    this.service.getAll({ withUser: false, withRepGroup: true, withGroup: false, withRepUser: true, userId: userId, groupId: groupId }).subscribe({
      next: (response: UserRep[]) => {
        this.source = response;
        this.loading = false;
      },
      error: (error: any) => { }
    });
  }
}