import { http } from '../http/http';
import { Repository } from './repository';
import { TaskSummaryResponse } from '../../domain/models/tasks/TaskSummaryResponse.interface';
import { TaskScheduleCountResponse } from '../../domain/models/tasks/TaskScheduleCountResponse.interface';
import { TaskResponse } from '../../domain/models/tasks/TaskResponse.interface';
import { Response } from '../../domain/models/Response.interface';
import { ScheduleType } from '../../domain/models/tasks/enums/ScheduleType.enum';
import { TaskType } from '../../domain/models/tasks/enums/TaskType.enum';

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

    async addTask(attributes : [], task_type: string): Promise<TaskResponse>{
        const response = await http.post<TaskResponse>(process.env.VUE_APP_ROOT_API + '/tasks/' + task_type, attributes);
        return response;
    }

    async getSummary(task_type: string) : Promise<TaskSummaryResponse>{
        const response = await http.get<TaskSummaryResponse>(process.env.VUE_APP_ROOT_API + '/tasks/' + task_type + '/summary');
        return response;
    }

    async deleteTask(task_id: string, task_type: string): Promise<Response>{
        const response = await http.delete<Response>(process.env.VUE_APP_ROOT_API + '/tasks/' + task_type + '/' + task_id);
        return response;
    }

    async getTask(task_id: string, task_type: string): Promise<TaskResponse>{
        const response = await http.get<TaskResponse>(process.env.VUE_APP_ROOT_API + '/tasks/' + task_type + '/' + task_id);
        return response;
    }

    async updateTask(idTask :string, task_type: string, attributes : any) : Promise<Response>{
        return await http.put<Response>(process.env.VUE_APP_ROOT_API + '/tasks/' + task_type + '/' + idTask, attributes);
    }

    async validateNewExtractTask(attributes : any) : Promise<Response>{
        return await http.post<Response>(process.env.VUE_APP_ROOT_API + '/tasks/extract/test', attributes);
    }

    async addSchedule(scheduleType: ScheduleType, attributes : any): Promise<Response>{
        return await http.post<Response>(process.env.VUE_APP_ROOT_API + '/tasks/' + TaskType.Schedule + '/' + scheduleType, attributes);
    }

    async getScheduleByTask(idTask :string): Promise<any>{
        return await http.get<TaskResponse>(process.env.VUE_APP_ROOT_API + '/tasks/schedule/task/' + idTask);
    }

    async updateSchedule(scheduleId: String, scheduleType: ScheduleType, attributes : any): Promise<Response>{
        return await http.put<Response>(process.env.VUE_APP_ROOT_API + '/tasks/' + TaskType.Schedule + '/' + scheduleType +  "/" + scheduleId, attributes);
    }

    async getCountScheduleTask(): Promise<TaskScheduleCountResponse>{
        return await http.get<TaskScheduleCountResponse>(process.env.VUE_APP_ROOT_API + '/tasks/schedule/count');
    }

    async getScheduleTaskList(): Promise<TaskSummaryResponse>{
        return await http.get<TaskSummaryResponse>(process.env.VUE_APP_ROOT_API + '/tasks/schedule');
    }
}