import {
  IsNotEmpty,
  IsOptional,
  IsString,
  IsBoolean,
  IsUUID,
  IsArray,
  MaxLength,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { CreateActivityTicketDto } from './create-activity-ticket.dto';
import { MediaItemDto, MediaListField } from '../../../common/media/media-item.dto';

export class CreateActivityDto {
  @IsUUID()
  @IsNotEmpty()
  destination_id: string;

  // short_code is auto-derived by the service from `name` and is
  // tenant-unique. Optional here for seeder/import back-compat.
  @IsString()
  @IsOptional()
  @MaxLength(50)
  short_code?: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  category: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(255)
  name: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(500)
  address: string;

  @IsString()
  @IsOptional()
  @MaxLength(255)
  location?: string;

  @IsString()
  @IsOptional()
  @MaxLength(20)
  cutoff_type?: string;

  @IsString()
  @IsOptional()
  @MaxLength(20)
  cutoff_value?: string;

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

  @IsArray()
  @IsOptional()
  maintenance_periods?: { start: string; end: string }[];

  @IsString()
  @IsOptional()
  @MaxLength(20)
  gps_latitude?: string;

  @IsString()
  @IsOptional()
  @MaxLength(20)
  gps_longitude?: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(255)
  contact_person: string;

  @IsString()
  @IsOptional()
  @MaxLength(20)
  contact_phone?: string;

  @IsString()
  @IsOptional()
  description?: string;

  @IsString()
  @IsOptional()
  special_instructions?: string;

  @IsString()
  @IsOptional()
  meeting_point?: string;

  @IsArray()
  @IsOptional()
  age_config?: { label: string; min_age: number; max_age: number }[];

  @IsArray()
  @IsOptional()
  @ValidateNested({ each: true })
  @Type(() => CreateActivityTicketDto)
  tickets?: CreateActivityTicketDto[];

  @MediaListField()
  media?: MediaItemDto[];

  @IsBoolean()
  @IsOptional()
  is_active?: boolean;

  /** Marks this activity as "includes transfer" — itinerary save
   *  requires a transport item on the same day. No pricing impact. */
  @IsBoolean()
  @IsOptional()
  has_transfer?: boolean;

  @IsBoolean()
  @IsOptional()
  is_special?: boolean;

  /**
   * WhatsApp body content injected via the wrapper's
   * {{service_body}} token when ops clicks Copy WA on a MD row
   * carrying this activity. Two audiences → two fields. See
   * migration 1783100000000 for the columns and the resolver
   * for how they land in the rendered message.
   */
  @IsString()
  @IsOptional()
  customer_whatsapp_body?: string;

  @IsString()
  @IsOptional()
  supplier_whatsapp_body?: string;
}
