import { AuthServiceService } from './auth-service.service';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { NgxSpinnerService } from 'ngx-spinner';
import { ToastrService } from 'ngx-toastr';


@Injectable({
  providedIn: 'root'
})
export class RolesService {

  constructor(private http: HttpClient,
      private authService: AuthServiceService,
      private spinner: NgxSpinnerService, 
      private toastr: ToastrService) { }

  //get roles list 
    getRolesList(pageId: number, currentPage: number, dataTableNumber: number){
      this.spinner.show();
      console.log(this.authService.pathApi +'/page_list/' + pageId + '/' + currentPage + '/' + dataTableNumber + '/all');
      return this.http.get(this.authService.pathApi +'/page_list/' + pageId + '/' + currentPage + '/' + dataTableNumber + '/all');
    }

    //get data user from searchBar 
    getDataUSerSearchBar(data, pageId, pagenationNumber, dataTableNumber) {
      console.log('url', this.authService.pathApi + '/page_list' + '/' + pageId + '/' + pagenationNumber + '/' + dataTableNumber + '/all/' + data);
      return this.http.get(this.authService.pathApi + '/page_list' + '/' + pageId + '/' + pagenationNumber + '/' + dataTableNumber + '/all/' + data);
    }

    //delete user 
    deleteUser(rolesIds) {
      console.log(rolesIds);
      return this.http.post(this.authService.pathApi + '/delete_role' , {'roles_id' : rolesIds});      
    };

    addRoles(dataRoles) {
      const dataRoleForm = dataRoles.value;
      return this.http.post(this.authService.pathApi + '/add_role', dataRoleForm);
    }

    editRole( dataRoleEdit,EditRoleId){
      const editData = dataRoleEdit;
      editData.id = EditRoleId;
      console.log(editData);
      return this.http.post(this.authService.pathApi + '/edit_role', editData);
    }

    getRoleData(roleId: number) {
      return this.http.get(this.authService.pathApi + '/get_role/' + roleId);
    }

  

    //get report pages inside roles
    get_report_pages_inside_roles(roleId: number) {
      return this.http.get(this.authService.pathApi + '/report_pages_inside_roles/' + roleId);
    }

    //get report of users inside roles
    get_report_users_inside_roles(roleId: number) {
      return this.http.get(this.authService.pathApi + '/report_users_inside_roles/' + roleId);
    }

    //get permissions list
    getPermissionList() {
      return this.http.get(this.authService.pathApi + '/permissions_list');
    }
    
}

