import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { UikitFlatpickrJalaliComponent } from '@/uikit';
import { nowJalali } from '@/utils';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { IPartnerChargeLicenseTransactionRequest } from '../models/chargeLicenseTransactions_io';
import { AdminPartnerChargeLicenseTransactionsService } from '../services/chargeLicenseTransactions.service';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';

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

  private readonly service = inject(AdminPartnerChargeLicenseTransactionsService);

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

  minDate = nowJalali();

  submitForm(payload: IPartnerChargeLicenseTransactionRequest) {
    return this.service.charge(this.partnerId, payload);
  }
}
