import {
  IsString,
  IsNotEmpty,
  IsUrl,
  IsArray,
  IsEnum,
  ArrayMinSize,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export enum WebhookEvent {
  CLIENT_CREATED = 'client.created',
  CLIENT_UPDATED = 'client.updated',
  TRAINING_CREATED = 'training.created',
  TRAINING_CANCELLED = 'training.cancelled',
  TRAINING_RESCHEDULED = 'training.rescheduled',
  TRAINING_COMPLETED = 'training.completed',
  SALE_CREATED = 'sale.created',
  SALE_PAID = 'sale.paid',
  FUNNEL_STAGE_CHANGED = 'funnel.stage_changed',
  FUNNEL_ASSIGNED = 'funnel.assigned',
  SCHEDULE_UPDATED = 'schedule.updated',
  MEMBERSHIP_EXPIRING = 'membership.expiring',
}

export class CreateWebhookDto {
  @ApiProperty({
    description: 'Webhook delivery URL',
    example: 'https://example.com/webhook',
  })
  @IsUrl()
  @IsNotEmpty()
  url: string;

  @ApiProperty({
    description: 'Events to subscribe to',
    enum: WebhookEvent,
    isArray: true,
    example: [WebhookEvent.CLIENT_CREATED, WebhookEvent.SALE_CREATED],
  })
  @IsArray()
  @ArrayMinSize(1)
  @IsEnum(WebhookEvent, { each: true })
  events: WebhookEvent[];
}
