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


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

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


  //get profile data
  getUserDataProfile() {
    this.http.get(this.authService.pathApi + '/profile').subscribe(
      (responce) => {
        this.authService.setDataUser(responce);
      },
      (error) => {console.log(error)},
    );
  }

  //get services data user
  getServicesData(id) {
    return this.http.get(this.authService.pathApi + '/get_user_services/' + id);
  }

  //get services of user
  getPagesPermetiotns(userId, serviceId){
    return this.http.get(this.authService.pathApi + '/get_user_pages_permissions/' + userId + '/' + serviceId);
  }


  //get adminstration
  getAdministration(){
    return this.http.get(this.authService.pathApi + '/adminstrations_list');
  }

  //get month
  getMonth(){
    return this.http.get(this.authService.pathApi + '/months_list');
  }

  //get departments
  getDepartments(adminstrationId) {
    return this.http.get(this.authService.pathApi + '/admin_departments/' + adminstrationId);
  }

  //get trainning service departments
  getTrainningServiceDepartments() {
    return this.http.get(this.authService.pathApi + '/departments_missed_supervisor');
  }

  //get all Supervisors
  getSupervisorsList(departId: number) {
    return this.http.get(this.authService.pathApi + '/users_belonsTo_training_department/' + departId);
  }
  
  //get all data of departments for trianning service
  getDepartmentData(departId: number) {
   return this.http.get(this.authService.pathApi + '/get_department/' + departId);
  }

  //get nationality
  getNationality() {
    return this.http.get(this.authService.pathApi + '/countries_list');
  }

  //get list data of page
  getPageData(id:number, currentPage, dataPageNumber) {
    console.log(this.authService.pathApi + '/page_list/' + id + '/' + currentPage + '/' + dataPageNumber + '/all');
    return this.http.get(this.authService.pathApi + '/page_list/' + id + '/' + currentPage + '/' + dataPageNumber + '/all');
  }

  //get job titile
  getJobTitle() {
    return this.http.get(this.authService.pathApi + '/job_titles_list');
  }

  //get contract list
  getContract(){
    return this.http.get(this.authService.pathApi + '/contract_types_list');
  }
  //get staff list
  getStaff(){
    return this.http.get(this.authService.pathApi + '/staff_list');
  }
  //get specialization
  getSpecialization() {
    return this.http.get(this.authService.pathApi + '/specialization_list');
  }

  //add user
  addUser(userForm, typePage: string){
    if(typePage == 'user'){
      return this.http.post(this.authService.pathApi + '/add_user', userForm);
    } else if(typePage == 'joinUs') {
      return this.http.post(this.authService.pathApi + '/add_join_us_user', userForm);
    }
  }

  //get user data
  onGetUserData(idUser:number, typePage: string){
    if(typePage == 'editUs') {
      return this.http.get(this.authService.pathApi + '/get_user/' + idUser);
    } else if(typePage == 'editJo') {
      return this.http.get(this.authService.pathApi + '/get_join_us_user/' + idUser);
    }
  }

  //edit data of user
  onEditUser(editDataUser, typePage: string){
    console.log(editDataUser);
    if(typePage == 'user'){
      return this.http.post(this.authService.pathApi + '/edit_user', editDataUser);
    } else if(typePage == 'joinUs') {
      return this.http.post(this.authService.pathApi + '/edit_join_us_user', editDataUser);
    }
  }

  onEditProfile(dataProfile) {
    return this.http.post(this.authService.pathApi + '/edit_profile', dataProfile);
  }

  //get data of pagenation
  getUserListPagenation(pageNumber:number , pageId: number) {
    const page = pageNumber;
    const pageID = pageId;
    return this.http.get(this.authService.pathApi + '/page_list/' + pageID + '/' + page);
  }

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

  //delete user
  deleteUser(userIds, typePageId) {
    if(typePageId == 1){
      console.log(userIds);
      return this.http.post(this.authService.pathApi + '/delete_user' , {'users_id' : userIds});

    } else if(typePageId == 9) {
      console.log(userIds);
      return this.http.post(this.authService.pathApi + '/delete_join_us_users' , {'users_id' : userIds});
    }

  }

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

  //get roles list
  getRolesList() {
   return this.http.get(this.authService.pathApi + '/roles_list');
  }

  //get report data
  onGetReportData(user_id:number) {
    return this.http.get(this.authService.pathApi + '/report_user_permissions/' + user_id);
  }

  //get indetities
  onGetIdentities() {
    return this.http.get(this.authService.pathApi + '/identities_list');
  }


}
