import { Component, EventEmitter, Input, Output, inject } from '@angular/core';

import { AbstractDialog } from '@/shared/abstractClasses/abstract-dialog';
import { IGoodResponse, SharedGoodFormComponent } from '@/shared/components/good';
import { IConsumerBusinessActivityGoodResponse } from '../../models/goods_io';
import { BusinessActivityGoodsService } from '../../services/goods.service';

@Component({
  selector: 'consumer-businessActivity-good-form',
  templateUrl: './form.component.html',
  imports: [SharedGoodFormComponent],
})
export class ConsumerBusinessActivityGoodFormComponent extends AbstractDialog {
  @Input({ required: true }) businessId!: string;
  @Input({ required: true }) guildId!: string;
  @Input() categoryId?: string;
  @Input() initialValues?: IConsumerBusinessActivityGoodResponse;
  @Input() editMode?: boolean;

  @Output() onSubmit = new EventEmitter<IGoodResponse>();

  private service = inject(BusinessActivityGoodsService);

  create = (payload: FormData) => {
    return this.service.create(this.businessId, payload);
  };

  update = (payload: FormData) => {
    return this.service.update(this.businessId, this.categoryId!, payload);
  };
}
