import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:sapaly_shop/constants/utils.dart';

import '../themes/app_theme.dart';

void httpErrorHandle({
  required http.Response response,
  required BuildContext context,
  required VoidCallback onSuccess,
}) {
  switch (response.statusCode) {
    case 200:
      onSuccess();
      break;
    case 400:
      showSnackBar(
        context,
        content: 'this_user_exists',
        backgroundColor: AppTheme.redColor,
        textColor: AppTheme.whiteColor,
      );
      break;
    case 500:
      showSnackBar(
        context,
        content: 'error_occured',
        backgroundColor: AppTheme.redColor,
        textColor: AppTheme.whiteColor,
      );
      break;
    default:
      showSnackBar(
        context,
        content: 'error_occured',
        backgroundColor: AppTheme.redColor,
        textColor: AppTheme.whiteColor,
      );
  }
}
