import 'package:intl/intl.dart';

class ValidatorUtil {
  static bool isValidEmail(String email) {
    if (RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(email)) {
      return true;
    } else {
      return false;
    }
  }

  static bool isValidPassword(String password) {
    if (password.length >= 8) {
      return true;
    } else {
      return false;
    }
  }

  static String toISO8601(String format, String value) {
    DateFormat dateFormat = DateFormat(format);
    DateTime dateTime = dateFormat.parse(value);

    return '${dateTime.toIso8601String()}Z';
  }

  static String toISO8601USA(String format, String value) {
    DateFormat dateFormat = DateFormat(format);
    DateTime dateTime = dateFormat.parse(value);
    String date = '${dateTime.toIso8601String()}Z';
    date = '${date.substring(0, 11)}03:00:00.000Z';

    return date;
  }

  static String toLocalDateTime(String format, String value) {
    DateFormat dateFormat = DateFormat(format);
    DateTime dateTime = dateFormat.parse(value);

    return DateFormat('dd/MM/yyyy HH:mm:ss').format(dateTime);
  }

  static String formatDateTimePicker(String dateTime) {
    List<String> parts = dateTime.split(' ');
    String datePart = parts[0];
    List<String> dateParts = datePart.split('-');
    String formattedDate = '${dateParts[2]}/${dateParts[1]}/${dateParts[0]}';
    return formattedDate;
  }
}
