import { http } from '../http/http';
import { Repository } from '../../infrastructure/repositories/repository'
import { JobResponse } from '../../domain/models/profiles/JobResponse.interface'
import { TaskType } from '../../domain/models/tasks/enums/TaskType.enum';
import { JobsSummaryResponse } from '../../domain/models/jobs/JobsSummaryResponse.interface';
import { JobCountResponse } from '../../domain/models/jobs/JobCountResponse.interface';
import { JobInfoResponse } from '../../domain/models/jobs/JobInfoResponse.interface';
import { Response } from '../../domain/models/Response.interface';

export class JobRepository extends Repository{
    constructor() {
        super();
    }

    async submitJob(idTaskSelected : String): Promise<JobResponse>{
        const response = await http.get<JobResponse>(process.env.VUE_APP_ROOT_API + '/jobs/submit/' + idTaskSelected);
        return response;
    }

    async getSummaryFromTask(taskType: TaskType): Promise<JobsSummaryResponse>{
        const response = await http.get<JobsSummaryResponse>(process.env.VUE_APP_ROOT_API + '/jobs/summary/' + taskType);
        return response;
    }
    async getCount(taskType: TaskType): Promise<JobCountResponse>{
        const response = await http.get<JobCountResponse>(process.env.VUE_APP_ROOT_API + '/jobs/results/' + taskType + '/count');
        return response;
    }

    async deleteJob(idJobSelected: String, taskType: TaskType): Promise<Response>{
        const response = await http.delete<Response>(process.env.VUE_APP_ROOT_API + '/jobs/results/' + taskType + '/' + idJobSelected );
        return response;
    }

    async stopJob(idJobSelected: String): Promise<Response>{
        const response = await http.get<Response>(process.env.VUE_APP_ROOT_API + '/jobs/stop/' + idJobSelected);
        return response;
    }

    async getInfoJob(idJobSelected: String, taskType: TaskType): Promise<JobInfoResponse>{
    const response = await http.get<JobInfoResponse>(process.env.VUE_APP_ROOT_API + '/jobs/results/' + taskType + '/info/' + idJobSelected );
        return response;
    }

    async getDetailJob(idJobSelected: String, taskType: TaskType): Promise<any>{
        const response = await http.get<any>(process.env.VUE_APP_ROOT_API + '/jobs/results/' + taskType + '/detail/' + idJobSelected );
            return response;
    }

    async getStatisticsExecutionJob(taskType: TaskType = TaskType.All): Promise<any>{
        const response = await http.get<any>(process.env.VUE_APP_ROOT_API + '/jobs/statistics/execution/' + taskType);
            return response;
    }

    async getQuestionsEvolve(idJobSelected: String): Promise<any>{
        const response = await http.get<any>(process.env.VUE_APP_ROOT_API + '/jobs/evolve/questions/' + idJobSelected);
            return response;
    }

    async saveQuestionsEvolve(idJobSelected: String, data: any ): Promise<any>{
        const response = await http.put<any>(process.env.VUE_APP_ROOT_API + '/jobs/evolve/questions/' + idJobSelected, data);
            return response;
    }

    async resumeJobEvolve(idJobSelected: String): Promise<any>{
        const response = await http.get<any>(process.env.VUE_APP_ROOT_API + '/jobs/resume/' + idJobSelected);
            return response;
    }

    async getSuggestedConfigs(idJobSelected: String): Promise<any>{
        const response = await http.get<any>(process.env.VUE_APP_ROOT_API + '/jobs/results/evolve/suggested_configs/' + idJobSelected);
            return response;
    }
}