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

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

  getByModuleId(moduleId: number, assigned: boolean = true): Observable<User[]> {
    const url = `${this.baseUrl}/ByModuleId/${moduleId}?assigned=${assigned}`;
    return this.http.get<User[]>(url, { withCredentials: true });
  }

  getByGroupId(groupId: number, assigned: boolean = true): Observable<User[]> {
    const url = `${this.baseUrl}/ByGroupId/${groupId}?assigned=${assigned}`;
    return this.http.get<User[]>(url, { withCredentials: true });
  }

  createByDir(createModel: DirUser): Observable<DirUser> {
    return this.http.post<DirUser>(`${this.baseUrl}/byDir`, createModel, { withCredentials: true });
  }
}