import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { Jobmaster } from './jobmaster';
import { debug } from 'util';
let header = new HttpHeaders();
header = header.set('Content-Type', 'application/json; charset=utf-8');

@Injectable({
    providedIn: 'root'
})
export class JobmasterService {
    baseUrl: string = environment.serviceUrl;
    constructor(private httpClient: HttpClient) { }


    Get(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/JobConfigurationApi')
    }

    getProjectCode(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/JobConfigurationApi/getProjectCode');
    }

    getProductType(projectid): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/JobConfigurationApi/getProductType?projectid=' + projectid);
    }

    /* getJobNo(projectid, projectdefinitionid): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/JobConfigurationApi/getJobNo?projectid='
            + projectid + '&projectdefinitionid=' + projectdefinitionid);
    } */

    Post(jobmaster: Jobmaster): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'api/JobConfigurationApi/add',
            jobmaster, { headers: header, observe: 'response' });
    }
    UploadJobInfoExcelFile(jobmaster: FormData): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'api/JobConfigurationApi/Addexceljob',
            jobmaster,{observe: 'response' });
    }

    Put(jobmaster: Jobmaster): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'api/JobConfigurationApi/Update',
            jobmaster, { headers: header, observe: 'response' });
    }

    getChapterType(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/ChapterTypeApi/GetActiveChapterType', { observe: 'response' });
    }
    getlotMasterById(jobid): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/JobMasterApi/getLotMasterById?jobid=' + jobid);

    }
    getJobProductType(userid): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/JobConfigurationApi/GetJobProductType?userid=' + userid);
    }
    getLotByJobId(data: any): Observable<any> {
        return this.httpClient.post<any>(this.baseUrl + 'api/LotApi/GetByJobId',
            data, { observe: 'response' });
    }
    postLotMaster(jobmaster: any): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'api/LotApi/Add',
            jobmaster, { headers: header, observe: 'response' });
    }
    UploadLotFile(jobmaster: FormData): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'api/LotApi/UploadLotFile',
            jobmaster, { observe: 'response' });
    }
    UploadLotInfoExcelFile(jobmaster: FormData): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'api/LotApi/UploadLotInfoExcelFile',
            jobmaster, { observe: 'response' });
    }
    getJobByProjectDefinitionid(projectdefinitionid): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/JobConfigurationApi/getJobByProjectDefinitionid?projectdefinitionid='
            + projectdefinitionid);
    }
    GetActiveState(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/StateCodeApi/GetActiveState');
    }
    GetActiveFrequency(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/FrequencyApi/GetActiveFrequency');
    }
    GetExcelTemplate(projectid, projecdefid): Observable<any>{
        return this.httpClient.post<any>(this.baseUrl+ 'api/JobConfigurationApi/GetExcelTemplate?projectid='
         + projectid + '&projecdefid='+ projecdefid, { observe: 'response' });
        
    }
    DeleteJob(jobid :number):Observable<any>{
        return this.httpClient.get<any>(this.baseUrl+ 'api/JobConfigurationApi/DeleteJob?jobid='+ jobid);
    }
}

