import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { first, map } from 'rxjs/operators';
import { environment } from '../../environments/environment';
const LINE_MESSAGE_URL = (id: string = null) => { return `${environment.apiUrl}/PushTextMessage?id=${id}` }
const GET_URL_PUSH_COMMAND_MESSAGE = (groupToken, command) => `LineMessage/PushCommandMessage?groupToken=${groupToken}&command=${command}`;


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

  constructor(private http: HttpClient) { }

  pushLineMessage(target: LineGroup, msg: string) {
    let targetId = null;
    switch (target) {
      case LineGroup.Ark:
        targetId = "Cac4ac5a8d7fc52daa444d71dc7c360a9";
        break;
      case LineGroup.ArkCowoker:
        targetId = "Ca20e3b65aa58e676815eb13c3222591a";
        break;
      case LineGroup.Chris:
        targetId = "U97e9e579a41a5222e33bf68a3bf479a0";

        break;
      default: break;
    }
    let msgObj = {
      message: msg,
      to: targetId
    }
    this.http.put<boolean>(LINE_MESSAGE_URL(msgObj.to),
      JSON.stringify(msgObj)
      //msg
      ,
      {
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        }
      }
    ).pipe(first()).subscribe(result => {

    });

    //Cac4ac5a8d7fc52daa444d71dc7c360a9 方舟小組 GroupID
    //Ca20e3b65aa58e676815eb13c3222591a 方舟小組同工 GroupID
    //"U97e9e579a41a5222e33bf68a3bf479a0" Chris
  }
  pushCommandMessage(pastoralDomainId: string, command: string) {

    this.http.get(GET_URL_PUSH_COMMAND_MESSAGE(pastoralDomainId, command)).pipe(first()).subscribe(result => {

    });
  }


}
export enum LineGroup {
  //[Description("Cac4ac5a8d7fc52daa444d71dc7c360a9")]
  Ark,
  //[Description("Ca20e3b65aa58e676815eb13c3222591a")]
  ArkCowoker,
  //[Description("U97e9e579a41a5222e33bf68a3bf479a0")]
  Chris,
}