import apiClient from "@/infrastructure/apiClient";
import apiPath from "@/infrastructure/apiPath";

export default {
  async getOrderProduction(model) {
    const params = JSON.parse(JSON.stringify(model));
    var result = await apiClient
      .post(apiPath.report.orderProduction, params)
      .then((r) => {
        if (r.data) return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },
  async getOrderProductionWithRevenue(model) {
    const params = JSON.parse(JSON.stringify(model));
    var result = await apiClient
      .post(apiPath.report.orderProductionWithRevenue, params)
      .then((r) => {
        if (r.data) return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },
  async getSaleRevenueStatistics(model) {
    const params = JSON.parse(JSON.stringify(model));

    var result = await apiClient
      .post(apiPath.report.saleRevenueStatistics, params)
      .then((r) => {
        if (r.data) return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },
  async getBankTransferSummaryBySale(model) {
    const params = JSON.parse(JSON.stringify(model));

    var result = await apiClient
      .post(apiPath.report.bankTransferSummaryBySale, params)
      .then((r) => {
        if (r.data) return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },
  async getOrderRevenueByCollectionDate(model) {
    const params = JSON.parse(JSON.stringify(model));
    try {
      const response = await apiClient.post(
        apiPath.report.orderRevenueByCollectionDate,
        params
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
  async prepareBankTransferSummaryBySaleModel() {
    try {
      const response = await apiClient.get(
        apiPath.report.prepareBankTransferSummaryBySaleModel
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
  async getOrderRevenueBySale(model) {
    const params = JSON.parse(JSON.stringify(model));
    try {
      const response = await apiClient.post(
        apiPath.report.orderRevenueBySale,
        params
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
  async getDriverProductivityByDate(model) {
    const params = JSON.parse(JSON.stringify(model));
    try {
      const response = await apiClient.post(
        apiPath.report.driverProductivityByDate,
        params
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
  async getOrderReportByRoute(model) {
    const params = JSON.parse(JSON.stringify(model));
    try {
      const response = await apiClient.post(
        apiPath.report.orderReportByRoute,
        params
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
  async getCustomerRevenueStatistics(model) {
    const params = JSON.parse(JSON.stringify(model));
    try {
      const response = await apiClient.post(
        apiPath.report.customerRevenueStatistics,
        params
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
  async getCustomerRevenuePermissions() {
    try {
      const response = await apiClient.get(
        apiPath.report.customerRevenuePermissions
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {
        Result: 2,
        CanSelectSale: false,
        CanSelectMultipleCustomers: false
      };
    }
  },
  async getFuelRefillReportByDriver(model) {
    const params = JSON.parse(JSON.stringify(model));
    try {
      const response = await apiClient.post(
        apiPath.report.fuelRefillReportByDriver,
        params
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
  async exportFuelRefillReportByDriver(model) {
    const params = JSON.parse(JSON.stringify(model));
    try {
      const response = await apiClient.post(
        apiPath.report.exportFuelRefillReportByDriver,
        params
      );
      return response.data || {};
    } catch (e) {
      console.log(e);
      return {};
    }
  },
};
