/**
 * Form Data Types
 * FE-TYPE-007: Add type definitions for all form inputs and validation
 *
 * Comprehensive type definitions for all form data used throughout
 * the application, ensuring type safety for form inputs and validation.
 */

import type { z } from 'zod';
import {
  loginSchema,
  registerSchema,
  forgotPasswordSchema,
  resetPasswordSchema,
  updateProfileSchema,
} from '@/schemas/validation';
import { profileSchema } from '@/features/profile/schemas/profileSchema';

/**
 * Login Form Data
 */
export type LoginFormData = z.infer<typeof loginSchema>;

/**
 * Register Form Data
 */
export type RegisterFormData = z.infer<typeof registerSchema>;

/**
 * Forgot Password Form Data
 */
export type ForgotPasswordFormData = z.infer<typeof forgotPasswordSchema>;

/**
 * Reset Password Form Data
 */
export type ResetPasswordFormData = z.infer<typeof resetPasswordSchema>;

/**
 * Profile Form Data
 */
export type ProfileFormData = z.infer<typeof profileSchema>;

/**
 * Update Profile Form Data
 */
export type UpdateProfileFormData = z.infer<typeof updateProfileSchema>;

/**
 * Playlist Form Data
 */
export interface PlaylistFormData {
  title: string;
  description?: string;
  is_public: boolean;
  cover_url?: string;
}

/**
 * Track Upload Form Data
 */
export interface TrackUploadFormData {
  title: string;
  artist: string;
  album?: string;
  genre: string;
  year?: number;
  file: File;
  cover_art?: File;
  is_public: boolean;
}

/**
 * Track Edit Form Data
 */
export interface TrackEditFormData {
  title?: string;
  artist?: string;
  album?: string;
  genre?: string;
  year?: number;
  is_public?: boolean;
}

/**
 * Comment Form Data
 */
export interface CommentFormData {
  content: string;
  parent_id?: string;
}

/**
 * Search Form Data
 */
export interface SearchFormData {
  query: string;
  type?: 'track' | 'playlist' | 'user' | 'all';
  filters?: {
    genre?: string;
    year?: number;
    duration_min?: number;
    duration_max?: number;
  };
}

/**
 * Settings Form Data
 */
export interface SettingsFormData {
  theme?: 'light' | 'dark' | 'system';
  language?: string;
  notifications?: {
    email?: boolean;
    push?: boolean;
    in_app?: boolean;
  };
  privacy?: {
    profile_visibility?: 'public' | 'private' | 'friends';
    show_email?: boolean;
    show_location?: boolean;
  };
  playback?: {
    autoplay?: boolean;
    default_volume?: number;
    quality?: 'low' | 'medium' | 'high';
  };
}

/**
 * Contact Form Data
 */
export interface ContactFormData {
  name: string;
  email: string;
  subject: string;
  message: string;
  category?: 'support' | 'bug' | 'feature' | 'other';
}

/**
 * Feedback Form Data
 */
export interface FeedbackFormData {
  rating: number; // 1-5
  comment?: string;
  category?: 'bug' | 'feature' | 'ui' | 'performance' | 'other';
  screenshots?: File[];
}

/**
 * Report Form Data
 */
export interface ReportFormData {
  type: 'user' | 'track' | 'playlist' | 'comment' | 'other';
  target_id: string;
  reason: string;
  description?: string;
  evidence?: File[];
}

/**
 * Share Form Data
 */
export interface ShareFormData {
  target_type: 'track' | 'playlist' | 'user';
  target_id: string;
  method: 'link' | 'email' | 'social';
  recipients?: string[]; // For email
  message?: string;
  permissions?: 'read' | 'write' | 'admin';
  expires_at?: string;
}

/**
 * Invite Form Data
 */
export interface InviteFormData {
  email: string;
  role?: 'viewer' | 'editor' | 'admin';
  message?: string;
}

/**
 * Filter Form Data (for lists/search)
 */
export interface FilterFormData {
  sort_by?: string;
  sort_order?: 'asc' | 'desc';
  date_range?: {
    start?: string;
    end?: string;
  };
  tags?: string[];
  exclude_tags?: string[];
}

/**
 * Bulk Action Form Data
 */
export interface BulkActionFormData {
  action: 'delete' | 'archive' | 'move' | 'tag' | 'share';
  item_ids: string[];
  target_id?: string; // For move/share
  tags?: string[]; // For tag action
}

/**
 * Import Form Data
 */
export interface ImportFormData {
  source: 'file' | 'url' | 'service';
  file?: File;
  url?: string;
  service?: 'spotify' | 'youtube' | 'soundcloud';
  service_id?: string;
  options?: {
    import_metadata?: boolean;
    import_artwork?: boolean;
    import_playlists?: boolean;
  };
}

/**
 * Export Form Data
 */
export interface ExportFormData {
  format: 'json' | 'csv' | 'xlsx' | 'pdf';
  include?: string[];
  filters?: FilterFormData;
}

/**
 * Generic Form Field
 */
export interface FormField<T = unknown> {
  name: string;
  type:
    | 'text'
    | 'email'
    | 'password'
    | 'number'
    | 'textarea'
    | 'select'
    | 'checkbox'
    | 'radio'
    | 'date'
    | 'time'
    | 'datetime'
    | 'file'
    | 'color'
    | 'range'
    | 'url';
  label: string;
  placeholder?: string;
  required?: boolean;
  disabled?: boolean;
  readonly?: boolean;
  defaultValue?: T;
  validation?: (value: T) => string | null;
  options?: Array<{ label: string; value: T }>;
  helpText?: string;
  error?: string;
}

/**
 * Form State
 */
export interface FormState<T = Record<string, unknown>> {
  data: T;
  errors: Record<string, string>;
  touched: Record<string, boolean>;
  isSubmitting: boolean;
  isValid: boolean;
  isDirty: boolean;
}

/**
 * Form Validation Result
 */
export interface FormValidationResult<T = unknown> {
  success: boolean;
  data?: T;
  errors?: Record<string, string[]>;
}

/**
 * Form Submission Handler
 */
export type FormSubmitHandler<T = Record<string, unknown>> = (
  data: T,
) => Promise<void> | void;

/**
 * Form Change Handler
 */
export type FormChangeHandler<T = unknown> = (name: string, value: T) => void;

/**
 * Form Error Handler
 */
export type FormErrorHandler = (errors: Record<string, string>) => void;
