
import 'package:flutter/material.dart';
import 'package:mc_common_app/api/api_client.dart';
import 'package:mc_common_app/classes/app_state.dart';
import 'package:mc_common_app/classes/consts.dart';
import 'package:mc_common_app/config/dependency_injection.dart';
import 'package:mc_common_app/models/general_models/m_response.dart';
import 'package:mc_common_app/models/services_models/item_model.dart';


abstract class ItemsRepo {
  Future<MResponse> createServiceItems(Map map);

  Future<ItemModel> getServiceItems(int serviceId);

  Future<MResponse> updateServiceItem(Map map);
}

class ItemsRepoImp implements ItemsRepo {
  @override
  Future<MResponse> createServiceItems(Map map) async {
    String t = AppState().getUser.data!.accessToken ?? "";
    debugPrint(t);
    return await injector.get<ApiClient>().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createItems, map, token: t);
  }

  @override
  Future<ItemModel> getServiceItems(int serviceId) async {
    var queryParameters = {
      "ServiceProviderServiceID": serviceId.toString(),
    };
    String? token = AppState().getUser.data?.accessToken;
    debugPrint(token);
    return await injector
        .get<ApiClient>()
        .getJsonForObject((json) => ItemModel.fromJson(json), ApiConsts.getServiceItems, queryParameters: queryParameters, token: AppState().getUser.data!.accessToken ?? "");
  }

  @override
  Future<MResponse> updateServiceItem(Map map) async {
    String t = AppState().getUser.data!.accessToken ?? "";
    debugPrint(t);
    return await injector.get<ApiClient>().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateServiceItem, map, token: t);

  }
}
