import {
  IsArray,
  IsNotEmpty,
  IsOptional,
  IsString,
  IsUppercase,
  Matches,
} from "class-validator";

export class CreateFunctionDto {
  @IsNotEmpty()
  @IsString()
  name!: string;

  @IsNotEmpty()
  @IsString()
  @Matches(
    /^\/(?:$|(?:[A-Za-z0-9._~-]+|:[A-Za-z0-9_]+)(?:\/(?:[A-Za-z0-9._~-]+|:[A-Za-z0-9_]+))*)$/,
    {
      message:
        "path must be a valid endpoint path (e.g. / or /hello/world/:id)",
    }
  )
  path!: string;

  @IsOptional()
  @IsNotEmpty()
  @IsString()
  code?: string;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  @IsUppercase({ each: true })
  methods?: string[];
}
