import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';

import '../model/login_model.dart';

class RemoteService{
  Future<LoginModel?> getLoginModel({required BuildContext context,required String username,required String password}) async{
    var dio = Dio(BaseOptions(
        contentType: "application/x-www-form-urlencoded",
        headers: {
          "Accept":"*/*",
          "Content-Type": "application/x-www-form-urlencoded",
        }
    ));
    String url = ("https://id.imes.test.myitsol.com/auth/realms/iMes/protocol/openid-connect/token");
    var response = await dio.post(url, options: Options(contentType: Headers.formUrlEncodedContentType),
        data: {
          "grant_type":"password",
          "username":username,
          "password":password,
          "client_id":"imes-app",
        }
    );
    if(response.statusCode == 200){
      var json = response.data;
      return LoginModel.fromJson(json);
    }
    return null;
  }
}