import { AxiosResponse } from 'axios';
import { AbpResponse } from '../../models/http/abpResponse';
import { ResultBase } from '../../models/http/resultBase';
import { Purchase } from '../../models/purchases/purchase';
import { PurchaseInput } from '../../models/purchases/purchaseInput';
import { HttpCommandBase } from '../abstract/httpCommandBase';
import { HttpMethod } from '../abstract/httpMethod';

export class PurchaseContentCommand extends HttpCommandBase<PurchaseInput, Purchase, ResultBase> {
    public endpoint = '/users/{externalId}/purchases';

    public method: HttpMethod = HttpMethod.Post;

    constructor(private contentId: string, private price: number, private onError: (rawResponse: AxiosResponse<AbpResponse<ResultBase>> | null) => void) {
        super();
    }

    public buildRequestContent(): PurchaseInput {
        return new PurchaseInput(this.contentId, this.price);
    }

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