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

@Injectable({
  providedIn: 'root',
})
export class AddPinService {
  private apiURL = environment.apiURL;
  private token = localStorage.getItem('auth_token');
  constructor(private http: HttpClient) {}

  addPin(pin: {
    title: string;
    description: string;
    location: string;
    files: any[];
  }) {
    const url = `${this.apiURL}/pin/add`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      Authorization: 'Bearer ' + this.token,
    });
    return this.http
      .post<any>(
        url,
        {
          title: pin.title,
          description: pin.description,
          location: pin.location,
          files: pin.files,
        },
        { headers }
      )
      .subscribe();
  }
}
