import { Injectable } from '@angular/core';
import { UserDetailsRequest } from './model/user-details.request';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { ConnectorService } from 'src/app/hmg-common/services/connector/connector.service';
import { UserLocalNotificationService } from 'src/app/hmg-common/services/user-local-notification/user-local-notification.service';
import { Observable } from 'rxjs';
import { Response } from 'src/app/hmg-common/services/models/response';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
import { ValidationRequest } from './model/validation.request';
import { SendValidationResponse } from './model/send-activation.response';

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

  public static sendActivation = 'Services/H2ORemainder.svc/REST/H2O_SendActivationCode';
  public static validateActivation = 'Services/H2ORemainder.svc/REST/H2O_ValidateActivationCode';
  public static sendBloodDonationSMS = 'services/PatientVarification.svc/REST/SendSMSForRegisteration';
  public static modal_success : boolean = false;
  public static code : string = "";
  public static mobile_number : string = "";
  public static country_code : string = "";
  public static national_id : string = "";

  constructor(
    public con: ConnectorService,
    public auth: AuthenticationService,
    public notifications: UserLocalNotificationService,
    public ts: TranslatorService
  ) {
  }

  public sendActivationCode(url: string,id: string, cellno: string, zip: string, onError: any, errorLabel: string)
    : Observable<SendValidationResponse> {
    const request = new UserDetailsRequest();
    request.MobileNumber = cellno;
    request.ZipCode = zip;
    request.IdentificationNo = id;
    request.PatientMobileNumber = cellno;   
    request.CellNumber = cellno;
    request.PatientIdentificationID = id;
    request.PatientMobileNumber = cellno;

    this.auth.setPublicFields(request);
    return this.con.post(url, request, onError, errorLabel);
  }

  public validateActivationCode(token: string, code: string, onError: any, errorLabel: string)
    : Observable<Response> {
    const request = new ValidationRequest();
    request.LogInTokenID = token;
    request.VerificationCode = code;
    this.auth.setPublicFields(request);
    return this.con.post(SMSService.validateActivation, request, onError, errorLabel);
  }
}
