import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { IPartnerChargeAccountRequest } from '../../models';
import { PartnerChargeAccountService } from '../../services/chargeAccount.service';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';

@Component({
  selector: 'partner-charge-account-form-dialog',
  templateUrl: './charge-account-form-dialog.component.html',
  imports: [
    SharedDialogComponent,
    ReactiveFormsModule,
    InputComponent,
    FormFooterActionsComponent,
  ],
})
export class PartnerChargeAccountFormDialogComponent extends AbstractFormDialog<
  IPartnerChargeAccountRequest,
  any
> {
  @Input({ required: true }) consumerId!: string;
  @Input({ required: true }) businessId!: string;

  private readonly service = inject(PartnerChargeAccountService);

  form = this.fb.group({
    quantity: [0, [Validators.required, Validators.min(1)]],
  });

  submitForm(payload: IPartnerChargeAccountRequest) {
    return this.service.charge(this.consumerId, this.businessId, payload);
  }
}
