import { Component } from '@angular/core';
import { UserTripJsonld, UserTripService } from "@app/core/api/v1";
import { userTripForm } from "@app/_forms/apiForms";
import { TranslateService } from "@ngx-translate/core";
import { Router } from "@angular/router";
import { ROUTE_USER_TRIPS } from "@app/app-routing.module";
import { AppHelperService } from "@app/_helpers/app-helper.service";
import { AbstractImageFormComponent } from "@app/_components/_abstract/abstract-image-form-component";
import { ImageUploadService } from "@app/_services/image-upload.service";

@Component({
    selector: 'app-user-trip-form',
    templateUrl: './user-trip-form.component.html',
    styleUrl: './user-trip-form.component.scss'
})
export class UserTripFormComponent extends AbstractImageFormComponent<UserTripJsonld> {

    protected readonly userTripForm = userTripForm;

    constructor(
        private userTripService: UserTripService,
        imageUploadService: ImageUploadService,
        private appHelperService: AppHelperService,
        translateService: TranslateService,
        router: Router
    ) {
        super(
            imageUploadService,
            userTripForm,
            undefined,
            (id: string | number, data: UserTripJsonld) =>
                this.userTripService.userTripsIdPatch(
                    id.toString(),
                    this.appHelperService.convertJsonldToJson(data)
                ),
            (id: string | number) => userTripService.userTripsIdDelete(id.toString()),
            'signatureIri',
            'signature.dbId',
            translateService,
            router
        );
        this.redirectAfterDelete = '/' + ROUTE_USER_TRIPS;
    }
}