// ignore_for_file: avoid_classes_with_only_static_members

import 'package:freezed_annotation/freezed_annotation.dart';

class Converters {
  static String? id(String? id) => id;
}

/// Converts ISO 8601 strings (from Supabase/PostgreSQL) to DateTime and back.
class TimestampConverter implements JsonConverter<DateTime, dynamic> {
  const TimestampConverter();

  @override
  DateTime fromJson(dynamic value) {
    if (value is String) return DateTime.parse(value);
    if (value is int) return DateTime.fromMillisecondsSinceEpoch(value);
    throw ArgumentError('Cannot convert $value to DateTime');
  }

  @override
  dynamic toJson(DateTime date) => date.toIso8601String();
}

class TimestampListConverter implements JsonConverter<List<DateTime>, List<dynamic>> {
  const TimestampListConverter();

  @override
  List<DateTime> fromJson(List<dynamic> values) {
    return values.map((v) => const TimestampConverter().fromJson(v)).toList();
  }

  @override
  List<dynamic> toJson(List<DateTime> dates) =>
      dates.map((d) => d.toIso8601String()).toList();
}
