import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Contact } from '../../../entities/contact';
import { environment } from '../../../../../environments/environment';

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

  constructor(private http: HttpClient) { }
  // async getCities(): Promise<any> {
  //   return await this.http.post("/api/web/cities/getCities", {})
  //     .toPromise() as any
  // }
  async getCities(): Promise<any> {
    // let parameter = { "latitude": latitude, "longitude": longitude }
    return await this.http.post("/api/web/towns/getTowns", {})
      .toPromise() as any
  }

  async getTowns(latitude: any, longitude: any): Promise<any> {
    let parameter = { "latitude": latitude, "longitude": longitude }
    return await this.http.post("/api/web/towns/getTowns", parameter)
      .toPromise() as any
  }

  async getCityByPincode(pincode: any): Promise<any> {
    var reqHeader = new HttpHeaders({ "Authorization": "CreditWeb" });
    let parameter = { "pincode": pincode }
    return await this.http.post("/api/customer/cities/getCityByPincode", parameter, { headers: reqHeader })
      .toPromise() as any
  }

  async getService(): Promise<any> {
    return await this.http.post("/api/web/services/getServices", {})
      .toPromise() as any
  }

  async getLeadsByContactNo(contactNo: number, serviceId: number): Promise<any> {
    let parameter = { "contactNo": contactNo, "serviceId": serviceId }
    return await this.http.post("/api/web/leads/getLeadsByContactNoAndServiceId", parameter)
      .toPromise() as any
  }

  async getEmploymentType(): Promise<any> {
    return await this.http.post("/api/web/employmentTypes/getEmploymentTypes", {})
      .toPromise() as any
  }

  async getdegree(): Promise<any> {
    return await this.http.post("/api/web/degrees/getDegrees", {})
      .toPromise() as any
  }

  async getCourses(): Promise<any> {
    return await this.http.post("/api/web/courses/getCourses", {})
      .toPromise() as any
  }

  async getCountries(): Promise<any> {
    return await this.http.post("/api/web/countries/getCountries", {})
      .toPromise() as any
  }

  async getPrimaryBank(): Promise<any> {
    return await this.http.post("/api/web/banks/getBanks", {})
      .toPromise() as any
  }

  async getDocument(): Promise<any> {
    return await this.http.post("/api/web/documents/getDocuments", {})
      .toPromise() as any
  }

  async getPartnerRoles(): Promise<any> {
    return await this.http.post("/api/web/roles/getPartnerRoles", {})
      .toPromise() as any
  }

  async getProfessionTypes(): Promise<any> {
    return await this.http.post("/api/web/professionTypes/getProfessionTypes", {})
      .toPromise() as any
  }

  async getCompanyTypes(): Promise<any> {
    return await this.http.post("/api/web/companyTypes/getCompanyTypes", {})
      .toPromise() as any
  }

  async getDocumentMaster(): Promise<any> {
    return await this.http.post("/api/customer/serviceDocuments/getDocumentMaster", {})
      .toPromise() as any
  }

  async insertContactDetail(contact: Contact): Promise<any> {
    return await this.http.post("/api/web/contactUs/insertContactUs", contact)
      .toPromise() as any
  }

  async insertNewsLetterSubscription(email: string): Promise<any> {
    return await this.http.post("/api/web/contactUs/insertNewsLetterSubscription", { "email": email })
      .toPromise() as any
  }

  async verifyContactNo(contactNo: string): Promise<any> {
    let parameter = JSON.parse(JSON.stringify({ "countryCode": "+91", "contactNo": contactNo }));
    return await this.http.post("/api/web/contactUs/insertContactUs", parameter).toPromise() as any;
  }

  async validateReferLink(linkKey: string): Promise<any> {
    let parameter = JSON.parse(JSON.stringify({ "linkKey": linkKey }));
    return await this.http.post("/api/web/referLink/validateReferLink", parameter).toPromise() as any;
  }

  async insertReferCustomer(contactNo: string, fullName: string, panCardNo: string, pincode: string, cityId: number, city: string, district: string, state: string, referenceUserId: number, referLinkId: number): Promise<any> {
    let parameter = JSON.parse(JSON.stringify({ "contactNo": contactNo, "fullName": fullName, "panCardNo": panCardNo, "pincode": pincode, "cityId": cityId, "city": city, "district": district, "state": state, "referenceUserId": referenceUserId, "referLinkId": referLinkId }));
    return await this.http.post("/api/web/referLink/insertReferCustomer", parameter).toPromise() as any;
  }

  // async (contactNo: number, serviceId: number): Promise<any> {
  //   let parameter = { "contactNo": contactNo, "serviceId": serviceId }
  //   return await this.http.post("/api/web/leads/getLeadsByContactNoAndServiceId", parameter)
  //     .toPromise() as any
  // }

  async referPartner(dsa: any): Promise<any> {
    return await this.http.post("/api/web/dsaSignUps/referPartner", dsa)
      .toPromise() as any
  }
}
