import { AxiosResponse } from 'axios';
import { AbpResponse } from '../../models/http/abpResponse';
import { Action } from '../../models/tasks/action';
import { TaskInput } from '../../models/tasks/taskInput';
import { HttpCommandBase } from '../abstract/httpCommandBase';
import { HttpMethod } from '../abstract/httpMethod';

export class PerformTaskCommand extends HttpCommandBase<TaskInput, Action, string> {
    public endpoint: string = '/users/{externalId}/actions';
    public method: HttpMethod = HttpMethod.Post;

    constructor(private taskInput: TaskInput, private onError: (rawResponse: AxiosResponse<AbpResponse<string>> | null) => void) {
        super();
    }

    public buildRequestContent(): TaskInput {
        return this.taskInput;
    }

    public handleError(rawResponse: AxiosResponse<AbpResponse<string>> | null): void {
        this.onError(rawResponse);
    }
}