import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { CouchService } from '../../data/services/couch.service';
import { VipCodeCreatedEvent } from 'src/modules/transaction/vip-code/domain/entities/event/vip-code-created.event';

@EventsHandler(VipCodeCreatedEvent)
export class VipCodeCreatedHandler
  implements IEventHandler<VipCodeCreatedEvent>
{
  constructor(private couchService: CouchService) {}

  async handle(event: VipCodeCreatedEvent) {
    const data = event.data.data;

    await this.couchService.createDoc(
      {
        _id: data.id,
        ...data,
      },
      'vip_code',
    );
  }
}
