import 'package:fotodocumentation/controller/base_controller.dart';
import 'package:fotodocumentation/dto/customer_dto.dart';

abstract interface class CustomerController {
  Future<List<CustomerListDto>> getAll(String query, String startsWith);

  Future<CustomerDto?> get({required int id});
}

class CustomerControllerImpl extends BaseController implements CustomerController {
  final String path = "customer";

  @override
  Future<List<CustomerListDto>> getAll(String query, String startsWith) async {
    String uriStr = '${uriUtils.getBaseUrl()}$path?query=$query&startsWith=$startsWith';
    return runGetListWithAuth(uriStr, (p0) {
      List<CustomerListDto> retVal = [];
      for (var elem in p0) {
        var entity = CustomerListDto.fromJson(elem);
        retVal.add(entity);
      }
      return retVal;
    });
  }

  @override
  Future<CustomerDto?> get({required int id}) {
    String uriStr = '${uriUtils.getBaseUrl()}$path/$id';
    return runGetWithAuth(uriStr, (json) => CustomerDto.fromJson(json));
  }
}
