import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {ApiResponse, ApiService} from './api';
import {HttpClient} from '@angular/common/http';
import {Portfolio} from '../models/portfolio.model';
import { environmentProd as env } from '../../environments/environment' ;

@Injectable({ providedIn: 'root' })
export class PortfolioService extends ApiService{


  getPortfolios(): Observable<ApiResponse<Portfolio[]>> {
    return this.get<ApiResponse<Portfolio[]>>(`/portfolios`);
  }

  createPortfolio(data: { name: string; domain: string }): Observable<ApiResponse<Portfolio>> {
    return this.post<ApiResponse<Portfolio>>(`/portfolios`, data);
  }

  uploadZip(portfolioId: number, file: File): Observable<ApiResponse> {
    const formData = new FormData();
    formData.append('file', file);
    return this.http.post<ApiResponse>(this.baseUrl + `/portfolios/${portfolioId}/upload`, formData);
  }

  deploy(portfolioId: number): Observable<ApiResponse> {
       console.log('Deploying portfolio with ID:', portfolioId);
      return this.http.post<ApiResponse>(this.baseUrl + `/portfolios/${portfolioId}/deploy`, {});
    }

    getRandomPortfolio() : Observable<ApiResponse>
    {
      return this.http.get<ApiResponse>(this.baseUrl + `/portfolio/random`, {});
    }
}
