import { AbstractFormDialog } from '@/shared/abstractClasses';
import {
  EconomicCodeComponent,
  FiscalCodeComponent,
  NameComponent,
  PartnerTokenComponent,
} from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { fieldControl } from '@/shared/constants/fields';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { IBusinessActivityRequest, IBusinessActivityResponse } from '../models';
import { BusinessActivitiesService } from '../services/main.service';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';

@Component({
  selector: 'consumer-businessActivity-form',
  templateUrl: './form.component.html',
  imports: [
    ReactiveFormsModule,
    SharedDialogComponent,
    FormFooterActionsComponent,
    NameComponent,
    EconomicCodeComponent,
    FiscalCodeComponent,
    PartnerTokenComponent,
  ],
})
export class ConsumerBusinessActivityFormComponent extends AbstractFormDialog<
  IBusinessActivityRequest,
  IBusinessActivityResponse
> {
  @Input({ required: true }) businessId!: string;
  private service = inject(BusinessActivitiesService);

  form = this.fb.group({
    name: fieldControl.name(this.initialValues?.name || ''),
    economic_code: fieldControl.economic_code(this.initialValues?.economic_code || ''),
    fiscal_code: fieldControl.fiscal_code(this.initialValues?.fiscal_code || ''),
    partner_token: fieldControl.partner_token(this.initialValues?.partner_token || ''),
  });

  override submitForm(payload: IBusinessActivityRequest) {
    return this.service.update(this.businessId, payload);
  }
}
