import { Component, OnInit } from '@angular/core';
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {IWrapped} from "../../models/ResponseWrap";
import * as api from "../../globals/api";

@Component({
  selector: 'app-encrypt',
  templateUrl: './encrypt.component.html',
  styleUrls: ['./encrypt.component.scss']
})
export class EncryptComponent implements OnInit {

  constructor(
    private http: HttpClient,
  ) { }

  tokenValue: string = '';
  userInput: string = '';
  payloadTemplate = {
    First_string: ''
  }

  outWrap(input: string){
    this.payloadTemplate.First_string = input
    this.getWrap(this.payloadTemplate).subscribe(response => {
      this.tokenValue = response.wrap_info.token;
    })
  }

  getWrap(dataToWrap: any){
    let headers: HttpHeaders = new HttpHeaders();
    headers = headers.append('X-Vault-Token', api.xVault_Token);
    headers = headers.append('X-Vault-Wrap-TTL', api.xVault_TTL);
    return this.http.post<IWrapped>(api.api_endpoint + '/wrap' , {dataToWrap}, {headers})
  }


  ngOnInit(): void {
  }


}
