import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
//8008202992

class RemoteData {
  final String loginUrl = 'http://vaman.plutokm.com/login';
  final String type     = "Content-Type";
  final String appjson  = "application/json";

  Future<String> getLoginRequest(
      String loginid, String pass, String token) async {
    Map<String, dynamic> body = {
      'login_id': loginid,
      'password': pass,
      'token': token,
      'os': Platform.isAndroid
          ? 'Android'
          : Platform.isIOS
              ? 'IOS'
              : 'Unknown',
    };
    if (kDebugMode) {
      print(body);
    }
    var client = http.Client();
    var res = await client.post(Uri.parse(loginUrl),
        headers: {type: appjson}, body: json.encode(body));
    if (res.statusCode == 200) {
      return res.body;
    } else {
      throw Exception('Status code was wrong$res.statusCode');
    }
  }

  Future<String?> uploadimage(File imagepath) async {
    try {
      final request = http.MultipartRequest(
          'POST', Uri.parse('http://vaman.plutokm.com/vasthram_mobile'));
      request.files
          .add(await http.MultipartFile.fromPath('image', imagepath.path));
      var response = await request.send();
      var responseString = await response.stream.bytesToString();
      if (kDebugMode) {
        print('Response   :$responseString');
      }
      if (response.statusCode == 200) {
        return responseString;
      } else {
        return responseString;
      }
    } catch (e) {
      if (kDebugMode) {
        print(e);
      }
    }
    return '';
  }
}
