import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { FleioApiService } from '../fleio-api.service';
import { ConfigService } from '../../config/config.service';
import { IMessageTemplateModel } from './model/message-template.model';
import { FleioId } from '../base-model/base-fleio-object.model';
import { Observable } from 'rxjs';


@Injectable({
  providedIn: 'root'
})
export class MessageTemplatesApiService extends FleioApiService<IMessageTemplateModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('message_templates'));
  }

  getEditableMessageTemplate(templateId: FleioId): Observable<IMessageTemplateModel[]> {
    return this.getAction('get_editable_message_templates', {template_id: templateId});
  }

  createTemplate(templateName: string, languageCode: string): Observable<any> {
    return this.postAction(null, {
      language: languageCode,
      name: templateName,
    });
  }

  updateTemplatesSet(templatesSet: IMessageTemplateModel[]): Observable<any> {
    return this.postAction('update_templates_set', templatesSet);
  }
}
