import { Injectable } from '@angular/core';
import { map } from 'rxjs';
import { HttpRequestService } from '../resources/http-request.service';

@Injectable({
  providedIn: 'root',
})
export class TableManagementService {
  private _url: string;

  constructor( private _httpRequestService: HttpRequestService ) {
    this._url = 'tabla-db';
  }

  public getTables() {
    return this._httpRequestService.getQuery(`${this._url}/consulta`).pipe(map((data:any) => data));
  }

  public registerTable(table: any) {
    return this._httpRequestService.postQuery(`${this._url}/registra`, table).pipe(map((data:any) => data));
  }

  public updateStateTable(table: any) {
    return this._httpRequestService.postQuery(`${this._url}/modifica-state`, table).pipe(map((data:any) => data));
  }

  public updateTable(obj_table: any) {
    return this._httpRequestService.postQuery(`${this._url}/modifica`, obj_table).pipe(map((data:any) => data));
  }

  // Obtener Columnas de Tablas
  public getColumns(data: any) {
    return this._httpRequestService.postQuery(`${this._url}/consulta-columnas`, data).pipe(map((data:any) => data));
  }
  // Obtener Columnas de Tablas
  public getColumnsExtra(data: any) {
    return this._httpRequestService.postQuery(`${this._url}/consulta-columnas-extra`, data).pipe(map((data:any) => data));
  }
}
