
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/generic_resp_model.dart';
import 'package:mc_common_app/models/services_models/item_model.dart';


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

  Future<ItemModel> getServiceItems(int serviceId);

  Future<GenericRespModel> updateServiceItem(Map map);
}

class ItemsRepoImp implements ItemsRepo {
  @override
  Future<GenericRespModel> createServiceItems(Map map) async {
    String t = AppState().getUser.data!.accessToken ?? "";
    return await injector.get<ApiClient>().postJsonForObject((json) => GenericRespModel.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;
    return await injector
        .get<ApiClient>()
        .getJsonForObject((json) => ItemModel.fromJson(json), ApiConsts.getServiceItems, queryParameters: queryParameters, token: AppState().getUser.data!.accessToken ?? "");
  }

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

  }
}
