// Data Transfer Objects for frontend use
import { UserRole, EventCategory, EventStatus, OrderItemType, PaymentMethod, NotificationType, MerchandiseCategory, EventMediaType, EventArtistRole, ApprovalStatus } from './enums';

// User DTOs
export interface CreateUserDto {
  id: string; // UUID generated by client
  username: string;
  email: string;
  phone?: string;
  password: string;
  role: UserRole; // Required, no default
  // Profile data based on role
  profileData?: CreateUserProfileDto | CreateArtistProfileDto | CreatePromotorProfileDto;
}

export interface LoginDto {
  username: string;
  password: string;
}

export interface UpdateUserDto {
  username?: string;
  email?: string;
  phone?: string;
  password?: string;
}

// Profile DTOs for all roles
export interface CreateUserProfileDto {
  fullName?: string;
  dateOfBirth?: string;
  gender?: string; // 'MALE', 'FEMALE', 'OTHER'
  profileImageUrl?: string;
  address?: string;
  city?: string;
  province?: string;
  postalCode?: string;
  nik?: string; // Optional encrypted NIK for regular users only
  preferences?: Record<string, any>; // User preferences for notifications, etc
}

export interface UpdateUserProfileDto {
  fullName?: string;
  dateOfBirth?: string;
  gender?: string; // 'MALE', 'FEMALE', 'OTHER'
  profileImageUrl?: string;
  address?: string;
  city?: string;
  province?: string;
  postalCode?: string;
  nik?: string; // Optional encrypted NIK for regular users only
  preferences?: Record<string, any>; // User preferences for notifications, etc
}

export interface CreatePromotorProfileDto {
  companyName: string;
  fullName: string;
  // NIK removed - not required for promotors
  phoneBusiness?: string;
  address?: string;
  city?: string;
  province?: string;
  postalCode?: string;
  bankName?: string;
  bankAccountNumber?: string;
  bankAccountName?: string;
  taxId?: string; // NPWP
  businessLicense?: string; // SIUP/NIB
  verificationDocuments?: any[];
}

export interface UpdatePromotorProfileDto {
  companyName?: string;
  fullName?: string;
  phoneBusiness?: string;
  address?: string;
  city?: string;
  province?: string;
  postalCode?: string;
  bankName?: string;
  bankAccountNumber?: string;
  bankAccountName?: string;
  taxId?: string;
  businessLicense?: string;
  verificationDocuments?: any[];
}

export interface CreateArtistProfileDto {
  stageName: string;
  fullName: string;
  // NIK removed - not required for artists
  bio?: string;
  genre?: string[]; // Array of ArtistGenre enum values
  profileImageUrl?: string;
  bannerImageUrl?: string;
  socialMedia?: Record<string, string>; // {"instagram": "@artist", "twitter": "@artist"}
  bankName?: string;
  bankAccountNumber?: string;
  bankAccountName?: string;
  verificationDocuments?: any[];
}

export interface UpdateArtistProfileDto {
  stageName?: string;
  fullName?: string;
  bio?: string;
  genre?: string[];
  profileImageUrl?: string;
  bannerImageUrl?: string;
  socialMedia?: Record<string, string>;
  bankName?: string;
  bankAccountNumber?: string;
  bankAccountName?: string;
  verificationDocuments?: any[];
}

export interface CreateAdminProfileDto {
  fullName: string;
  employeeId?: string;
  department?: string;
  position?: string;
  phoneNumber?: string;
  emergencyContact?: string;
  permissions?: string[];
}

export interface UpdateAdminProfileDto {
  fullName?: string;
  employeeId?: string;
  department?: string;
  position?: string;
  phoneNumber?: string;
  emergencyContact?: string;
  permissions?: string[];
}

// Event DTOs
export interface CreateEventDto {
  title: string;
  description: string;
  shortDescription?: string;
  startDate: string;
  endDate: string;
  location: string;
  venueName?: string;
  venueAddress?: string;
  venueCapacity?: number;
  category: EventCategory;
  promotorId?: string;
  imageUrl?: string;
  bannerImageUrl?: string;
  imageObjectKey?: string;
  bannerObjectKey?: string;
  galleryObjectKeys?: string[];
  maxCapacity?: number;
  priceStartFrom?: number;
  isFeatured?: boolean;
  isHighlight?: boolean;
  highlightOrder?: number;
  minAge?: number;
  contactInfo?: Record<string, any>;
  terms?: string;
  artistIds?: string[];
  tags?: string[];
  metadata?: Record<string, any>;
}

export interface UpdateEventDto {
  title?: string;
  description?: string;
  shortDescription?: string;
  startDate?: string;
  endDate?: string;
  location?: string;
  venueName?: string;
  venueAddress?: string;
  venueCapacity?: number;
  category?: EventCategory;
  status?: EventStatus;
  imageUrl?: string;
  bannerImageUrl?: string;
  imageObjectKey?: string;
  bannerObjectKey?: string;
  galleryObjectKeys?: string[];
  maxCapacity?: number;
  priceStartFrom?: number;
  isFeatured?: boolean;
  isHighlight?: boolean;
  highlightOrder?: number;
  minAge?: number;
  contactInfo?: Record<string, any>;
  terms?: string;
  artistIds?: string[];
  tags?: string[];
  metadata?: Record<string, any>;
}

export interface CreateEventScheduleDto {
  eventId: string;
  title: string;
  description?: string;
  startTime: string;
  endTime: string;
  location?: string;
  speakers?: string[];
  isBreak?: boolean;
  order: number;
}

export interface UpdateEventScheduleDto {
  title?: string;
  description?: string;
  startTime?: string;
  endTime?: string;
  location?: string;
  speakers?: string[];
  isBreak?: boolean;
  order?: number;
}

// Event Query DTO
export interface EventQueryDto {
  page?: number;
  limit?: number;
  search?: string;
  category?: EventCategory;
  status?: EventStatus;
  location?: string;
  startDate?: string;
  endDate?: string;
  organizerId?: string;
  isFeatured?: boolean;
  tags?: string[];
  sortBy?: string;
  sortOrder?: 'ASC' | 'DESC';
}

// Event Media DTOs
export interface CreateEventMediaDto {
  eventId: string;
  type: EventMediaType;
  url: string;
  title?: string;
  description?: string;
  order?: number;
  metadata?: Record<string, any>;
}

export interface UpdateEventMediaDto {
  type?: EventMediaType;
  url?: string;
  title?: string;
  description?: string;
  order?: number;
  metadata?: Record<string, any>;
}

// Event Artist DTOs
export interface CreateEventArtistDto {
  eventId: string;
  artistId?: string;
  name: string;
  role: EventArtistRole;
  bio?: string;
  imageUrl?: string;
  socialMedia?: Record<string, string>;
  order?: number;
  metadata?: Record<string, any>;
}

export interface UpdateEventArtistDto {
  artistId?: string;
  name?: string;
  role?: EventArtistRole;
  bio?: string;
  imageUrl?: string;
  socialMedia?: Record<string, string>;
  order?: number;
  metadata?: Record<string, any>;
}

// Event Review DTOs
export interface CreateEventReviewDto {
  eventId: string;
  userId?: string;
  rating: number;
  title?: string;
  comment?: string;
  isAnonymous?: boolean;
  metadata?: Record<string, any>;
}

export interface UpdateEventReviewDto {
  rating?: number;
  title?: string;
  comment?: string;
  isAnonymous?: boolean;
  metadata?: Record<string, any>;
}

// Ticket DTOs
export interface CreateTicketDto {
  ticketTypeId: string;
  orderId?: string;
  userId?: string;
  customerInfo: {
    name: string;
    email: string;
    phone?: string;
  };
  seatNumber?: string;
  metadata?: Record<string, any>;
}

export interface UpdateTicketDto {
  status?: string;
  seatNumber?: string;
  metadata?: Record<string, any>;
}

export interface TicketQueryDto {
  page?: number;
  limit?: number;
  eventId?: string;
  userId?: string;
  status?: string;
  ticketTypeId?: string;
  sortBy?: string;
  sortOrder?: 'ASC' | 'DESC';
}

export interface CreateTicketTypeDto {
  eventId: string;
  name: string;
  description?: string;
  price: number;
  quantityTotal: number;
  saleStartDate?: string;
  saleEndDate?: string;
  benefits?: string[];
  hasSeating?: boolean;
  metadata?: Record<string, any>;
}

export interface UpdateTicketTypeDto {
  name?: string;
  description?: string;
  price?: number;
  quantityTotal?: number;
  saleStartDate?: string;
  saleEndDate?: string;
  benefits?: string[];
  hasSeating?: boolean;
  metadata?: Record<string, any>;
}

export interface CreateTicketReservationDto {
  ticketTypeId: string;
  quantity: number;
  customerInfo: {
    name: string;
    email: string;
    phone?: string;
  };
  expiresAt?: string;
}

// Order DTOs
export interface OrderItemDto {
  itemType: OrderItemType;
  itemId: string;
  itemName: string;
  itemDescription?: string;
  unitPrice: number;
  quantity: number;
  discountAmount?: number;
  itemData?: Record<string, any>;
}

export interface CreateOrderDto {
  items: OrderItemDto[];
  customerInfo: {
    name: string;
    email: string;
    phone?: string;
    address?: string;
  };
  shippingInfo?: {
    address: string;
    city: string;
    postalCode: string;
    country: string;
    method?: string;
  };
  discountCode?: string;
  notes?: string;
  metadata?: Record<string, any>;
}

export interface UpdateOrderDto {
  status?: string;
  customerInfo?: {
    name?: string;
    email?: string;
    phone?: string;
    address?: string;
  };
  shippingInfo?: {
    address?: string;
    city?: string;
    postalCode?: string;
    country?: string;
    method?: string;
    trackingNumber?: string;
  };
  notes?: string;
  metadata?: Record<string, any>;
}

export interface ApplyDiscountDto {
  orderId: string;
  discountCode: string;
}

// Payment DTOs
export interface CreatePaymentDto {
  orderId: string;
  amount: number;
  currency?: string;
  method: PaymentMethod;
  provider?: string;
  returnUrl?: string;
  metadata?: Record<string, any>;
}

export interface UpdatePaymentDto {
  status?: string;
  paidAt?: string;
  gatewayTransactionId?: string;
  gatewayResponse?: Record<string, any>;
  metadata?: Record<string, any>;
}

export interface CreatePaymentRefundDto {
  paymentId: string;
  amount?: number;
  reason: string;
  metadata?: Record<string, any>;
}

// Notification DTOs
export interface CreateNotificationDto {
  recipientId: string;
  type: NotificationType;
  title: string;
  message: string;
  data?: Record<string, any>;
  scheduledAt?: string;
  metadata?: Record<string, any>;
}

export interface UpdateNotificationDto {
  title?: string;
  message?: string;
  data?: Record<string, any>;
  isRead?: boolean;
  scheduledAt?: string;
  metadata?: Record<string, any>;
}

export interface BulkNotificationDto {
  recipientIds: string[];
  type: NotificationType;
  title: string;
  message: string;
  data?: Record<string, any>;
  scheduledAt?: string;
  metadata?: Record<string, any>;
}

// Merchandise DTOs
export interface CreateMerchandiseDto {
  name: string;
  description?: string;
  shortDescription?: string;
  category: MerchandiseCategory;
  subcategory?: string;
  tags?: string[];
  eventId?: string;
  basePrice: number;
  salePrice?: number;
  costPrice?: number;
  trackInventory?: boolean;
  totalStock?: number;
  images?: string[];
  weight?: number;
  dimensions?: {
    length: number;
    width: number;
    height: number;
  };
  metadata?: Record<string, any>;
}

export interface UpdateMerchandiseDto {
  name?: string;
  description?: string;
  shortDescription?: string;
  category?: MerchandiseCategory;
  subcategory?: string;
  tags?: string[];
  basePrice?: number;
  salePrice?: number;
  costPrice?: number;
  trackInventory?: boolean;
  totalStock?: number;
  images?: string[];
  weight?: number;
  dimensions?: {
    length?: number;
    width?: number;
    height?: number;
  };
  metadata?: Record<string, any>;
}

export interface CreateMerchandiseVariantDto {
  merchandiseId: string;
  name: string;
  sku?: string;
  price?: number;
  stock: number;
  attributes: Record<string, string>;
  images?: string[];
  isActive?: boolean;
}

export interface CreateMerchandiseOrderDto {
  merchandiseId: string;
  variantId?: string;
  quantity: number;
  customerInfo: {
    name: string;
    email: string;
    phone?: string;
    address: string;
  };
  shippingMethod?: string;
  notes?: string;
}

// File Upload DTOs
export interface FileUploadDto {
  file: File;
  category?: string;
  metadata?: Record<string, any>;
}

export interface MultipleFileUploadDto {
  files: File[];
  category?: string;
  metadata?: Record<string, any>;
}

// Search and Filter DTOs
export interface SearchDto {
  query: string;
  filters?: Record<string, any>;
  page?: number;
  limit?: number;
  sortBy?: string;
  sortOrder?: 'ASC' | 'DESC';
}

export interface EventFilterDto {
  category?: EventCategory;
  status?: EventStatus;
  location?: string;
  startDate?: string;
  endDate?: string;
  minPrice?: number;
  maxPrice?: number;
  organizerId?: string;
  isFeatured?: boolean;
  tags?: string[];
}

export interface MerchandiseFilterDto {
  category?: MerchandiseCategory;
  minPrice?: number;
  maxPrice?: number;
  inStock?: boolean;
  eventId?: string;
  ownerId?: string;
  tags?: string[];
}

// Analytics DTOs
export interface AnalyticsQueryDto {
  startDate: string;
  endDate: string;
  granularity?: 'day' | 'week' | 'month';
  filters?: Record<string, any>;
}

export interface ReportQueryDto {
  type: 'sales' | 'events' | 'users' | 'tickets';
  startDate: string;
  endDate: string;
  format?: 'json' | 'csv' | 'pdf';
  filters?: Record<string, any>;
}

// Approval DTOs
export interface ApproveEventDto {
  eventId: string;
  approvedBy: string;
  approvalNotes?: string;
  metadata?: Record<string, any>;
}

export interface RejectEventDto {
  eventId: string;
  rejectedBy: string;
  rejectionReason: string;
  rejectionNotes?: string;
  metadata?: Record<string, any>;
}

export interface EventApprovalQueryDto {
  page?: number;
  limit?: number;
  status?: ApprovalStatus;
  approvedBy?: string;
  rejectedBy?: string;
  startDate?: string;
  endDate?: string;
  sortBy?: string;
  sortOrder?: 'ASC' | 'DESC';
}

// Settings System DTOs
export interface CreateSystemSettingDto {
  category: string;
  key: string;
  value: any;
  dataType: string;
  description?: string;
  isEncrypted?: boolean;
  requiresRestart?: boolean;
  isActive?: boolean;
  environment?: string;
  validation?: {
    required?: boolean;
    min?: number;
    max?: number;
    pattern?: string;
    enum?: string[];
    customValidator?: string;
  };
  metadata?: {
    group?: string;
    order?: number;
    tags?: string[];
    icon?: string;
    helpText?: string;
    warningMessage?: string;
  };
  defaultValue?: string;
  isReadOnly?: boolean;
  isSystemGenerated?: boolean;
}

export interface UpdateSystemSettingDto {
  value?: any;
  description?: string;
  isActive?: boolean;
  validation?: {
    required?: boolean;
    min?: number;
    max?: number;
    pattern?: string;
    enum?: string[];
    customValidator?: string;
  };
  metadata?: {
    group?: string;
    order?: number;
    tags?: string[];
    icon?: string;
    helpText?: string;
    warningMessage?: string;
  };
  changeReason?: string;
}

export interface BulkUpdateSettingsDto {
  settings: Array<{
    category: string;
    key: string;
    value: any;
    changeReason?: string;
  }>;
  source?: string;
  batchId?: string;
}

export interface SystemSettingQueryDto {
  page?: number;
  limit?: number;
  category?: string;
  environment?: string;
  isActive?: boolean;
  isEncrypted?: boolean;
  requiresRestart?: boolean;
  search?: string;
  sortBy?: string;
  sortOrder?: 'ASC' | 'DESC';
}

export interface CreateFeatureFlagDto {
  name: string;
  displayName: string;
  description?: string;
  type?: string;
  status?: string;
  scope?: string;
  isEnabled?: boolean;
  rolloutPercentage?: number;
  targetCriteria?: {
    userIds?: string[];
    roles?: string[];
    countries?: string[];
    cities?: string[];
    deviceTypes?: string[];
    browserTypes?: string[];
    ipRanges?: string[];
    userSegments?: string[];
    customAttributes?: Record<string, any>;
  };
  environment?: string;
  startDate?: string;
  endDate?: string;
  configuration?: {
    fallbackValue?: any;
    dependencies?: string[];
    conflictsWith?: string[];
    variants?: Array<{
      name: string;
      value: any;
      percentage: number;
    }>;
  };
  metadata?: {
    category?: string;
    tags?: string[];
    owner?: string;
    jiraTicket?: string;
    documentation?: string;
    priority?: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
  };
  isPermanent?: boolean;
}

export interface UpdateFeatureFlagDto {
  displayName?: string;
  description?: string;
  status?: string;
  isEnabled?: boolean;
  rolloutPercentage?: number;
  targetCriteria?: {
    userIds?: string[];
    roles?: string[];
    countries?: string[];
    cities?: string[];
    deviceTypes?: string[];
    browserTypes?: string[];
    ipRanges?: string[];
    userSegments?: string[];
    customAttributes?: Record<string, any>;
  };
  startDate?: string;
  endDate?: string;
  configuration?: {
    fallbackValue?: any;
    dependencies?: string[];
    conflictsWith?: string[];
    variants?: Array<{
      name: string;
      value: any;
      percentage: number;
    }>;
  };
  metadata?: {
    category?: string;
    tags?: string[];
    owner?: string;
    jiraTicket?: string;
    documentation?: string;
    priority?: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
  };
  isPermanent?: boolean;
}

export interface FeatureFlagQueryDto {
  page?: number;
  limit?: number;
  status?: string;
  scope?: string;
  environment?: string;
  isEnabled?: boolean;
  search?: string;
  category?: string;
  tags?: string[];
  sortBy?: string;
  sortOrder?: 'ASC' | 'DESC';
}

export interface CreateEmailTemplateDto {
  templateKey: string;
  name: string;
  description?: string;
  type?: string;
  subject: string;
  htmlContent: string;
  textContent?: string;
  format?: string;
  variables?: Array<{
    name: string;
    type: 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object';
    required: boolean;
    defaultValue?: any;
    description?: string;
    validation?: {
      pattern?: string;
      min?: number;
      max?: number;
      enum?: string[];
    };
  }>;
  sampleData?: Record<string, any>;
  priority?: string;
  isDefault?: boolean;
  isActive?: boolean;
  fromName?: string;
  fromEmail?: string;
  replyTo?: string;
  categories?: string[];
  tags?: string[];
  settings?: {
    trackOpens?: boolean;
    trackClicks?: boolean;
    unsubscribeLink?: boolean;
    customHeaders?: Record<string, string>;
    attachments?: Array<{
      name: string;
      url: string;
      contentType: string;
    }>;
  };
  localization?: Record<string, {
    subject: string;
    htmlContent: string;
    textContent?: string;
  }>;
  parentTemplateId?: string;
  metadata?: {
    designer?: string;
    designTool?: string;
    thumbnailUrl?: string;
    previewUrl?: string;
    testData?: Record<string, any>;
  };
}

export interface UpdateEmailTemplateDto {
  name?: string;
  description?: string;
  subject?: string;
  htmlContent?: string;
  textContent?: string;
  format?: string;
  variables?: Array<{
    name: string;
    type: 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object';
    required: boolean;
    defaultValue?: any;
    description?: string;
    validation?: {
      pattern?: string;
      min?: number;
      max?: number;
      enum?: string[];
    };
  }>;
  sampleData?: Record<string, any>;
  priority?: string;
  isDefault?: boolean;
  isActive?: boolean;
  fromName?: string;
  fromEmail?: string;
  replyTo?: string;
  categories?: string[];
  tags?: string[];
  settings?: {
    trackOpens?: boolean;
    trackClicks?: boolean;
    unsubscribeLink?: boolean;
    customHeaders?: Record<string, string>;
    attachments?: Array<{
      name: string;
      url: string;
      contentType: string;
    }>;
  };
  localization?: Record<string, {
    subject: string;
    htmlContent: string;
    textContent?: string;
  }>;
  metadata?: {
    designer?: string;
    designTool?: string;
    thumbnailUrl?: string;
    previewUrl?: string;
    testData?: Record<string, any>;
  };
}

export interface EmailTemplateQueryDto {
  page?: number;
  limit?: number;
  type?: string;
  status?: string;
  isActive?: boolean;
  categories?: string[];
  tags?: string[];
  search?: string;
  sortBy?: string;
  sortOrder?: 'ASC' | 'DESC';
}

export interface SettingsExportDto {
  categories?: string[];
  environment?: string;
  includeEncrypted?: boolean;
  format?: 'JSON' | 'YAML' | 'ENV';
}

export interface SettingsImportDto {
  settings: Array<{
    category: string;
    key: string;
    value: any;
    dataType?: string;
    description?: string;
    isEncrypted?: boolean;
    requiresRestart?: boolean;
    environment?: string;
  }>;
  overwriteExisting?: boolean;
  validateOnly?: boolean;
  source?: string;
}

export interface CreateSettingsHistoryDto {
  settingId: string;
  settingKey: string;
  settingCategory: string;
  oldValue: any;
  newValue: any;
  changeType: string;
  source: string;
  changeReason?: string;
  changedBy: string;
  ipAddress?: string;
  metadata?: Record<string, any>;
}

export interface SettingsHistoryQueryDto {
  page?: number;
  limit?: number;
  changeType?: string;
  source?: string;
  settingCategory?: string;
  settingKey?: string;
  changedBy?: string;
  startDate?: string;
  endDate?: string;
  sortOrder?: 'ASC' | 'DESC';
}