import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ModuleOfUser } from '../../models/user-management.api.models';
import { ApiService } from './user-management.api.service';
import { Observable, firstValueFrom } from 'rxjs';
import { UrlService } from './url.service';

@Injectable({
  providedIn: 'root'
})
export class ModuleOfUserService extends ApiService<ModuleOfUser> {
  constructor(http: HttpClient, urlService : UrlService) {
    super(http, urlService.apiRoute.moduleOfUser);
  }

  deleteByModuleGroupId(moduleId: number, userId: number): Observable<any> {
    const url = `${this.baseUrl}?moduleId=${moduleId}&userId=${userId}`;
    return this.http.delete<any>(url, { withCredentials: true });
  }

  async getByUsername(username: string): Promise<ModuleOfUser[]> {
    const url = `${this.baseUrl}?username=${username}`;
    return await firstValueFrom(this.http.get<ModuleOfUser[]>(url, { withCredentials: true }));
  }
}