import { isValid, parseISO } from 'date-fns';

export const VALID_STATUSES = ['open', 'closed', 'resolved', 'pending', 'recommended_for_fining', 'fined', 'escalated'];
export const OPEN_STATUSES = ['open', 'escalated', 'recommended_for_fining'];

export const NOTICE_LEVELS = {
  FIRST: 'First Notice',
  SECOND: 'Second Notice',
  THIRD: 'Third & Final Notice'
};

/**
 * Validates a single timeline entry object.
 * @param {Object} entry - The entry to validate
 * @returns {Array} - Array of error strings, empty if valid
 */
export const validateTimelineEntry = (entry) => {
  const errors = [];

  // 1. Validate Date
  if (!entry.entry_date) {
    errors.push("Date is required.");
  } else {
    // Check if it's a valid date string
    const date = new Date(entry.entry_date);
    if (isNaN(date.getTime())) {
      errors.push("Invalid date format.");
    }
  }

  // 2. Validate Status
  if (!entry.status) {
    errors.push("Status is required.");
  } else if (!VALID_STATUSES.includes(entry.status.toLowerCase())) {
    errors.push(`Invalid status. Must be one of: ${VALID_STATUSES.join(', ')}.`);
  }

  // 3. Validate Description
  if (!entry.description || typeof entry.description !== 'string' || entry.description.trim() === '') {
    errors.push("Description is required.");
  }

  // 4. Validate Recorded By
  if (!entry.recorded_by_name || typeof entry.recorded_by_name !== 'string' || entry.recorded_by_name.trim() === '') {
    errors.push("Recorded By name is required.");
  }

  return errors;
};