import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';
import { Observable } from 'rxjs';

interface XmlXsdValidationRequest {
  xmlContent: string;
  SchemaFilePath: string;
}

interface XmldtdValidationRequest {
  xmlContent: string;
  SchemaFilePath: string;
}

interface XmlxsltValidationRequest {
  xmlContent: string;
  SchemaFilePath: string;
  OutputPath: string;
  fileName: string;
}

@Injectable({
  providedIn: 'root'
})
export class XmlvalidationService {
  private apiUrl = `${environment.apiUrl}/XmlValidatorApi`; // Update based on your API URL


  constructor(private http: HttpClient) {}

  ValidateXsd(xmlContent: string, SchemaFilePath: string): Observable<any> {    
    const validationRequest: XmlXsdValidationRequest = {
      xmlContent,
      SchemaFilePath     
    }; 
    return this.http.post<any>(`${this.apiUrl}/validate-xsd`,  validationRequest );
  }

  ValidateDtd(xmlContent: string, SchemaFilePath: string): Observable<any> {     
    const validationRequest: XmldtdValidationRequest = {
      xmlContent,
      SchemaFilePath     
    }; 
    return this.http.post<any>(`${this.apiUrl}/validate-dtd`,  validationRequest );
  }

  Transform(xmlContent: string, SchemaFilePath: string, OutputPath: string, fileName : string): Observable<any> {     
    const validationRequest: XmlxsltValidationRequest = {
      xmlContent,
      SchemaFilePath,
      OutputPath,
      fileName 
    }; 
    return this.http.post<any>(`${this.apiUrl}/convert-text`,  validationRequest );
  }

   DocumentPath(documentType: string, projectDefinitionId: any) : Observable<string> {    
      return this.http.get(this.apiUrl + '/document-path?documentType=' + documentType + '&projectDefinitionId= '+ projectDefinitionId, { responseType: 'text' });
    }

}
