"use strict";

const adminTradeHistoryService = require("../../services/admin/tradeHistoryService");
const ApiResponse = require("../../utils/apiResponse");
const { asyncHandler } = require("../../middleware/errorHandler");

exports.listTrades = asyncHandler(async (req, res) => {
  const data = await adminTradeHistoryService.listTrades(req.query);
  ApiResponse.success(res, data);
});

exports.getTradeById = asyncHandler(async (req, res) => {
  const { tradeId } = req.params;
  const data = await adminTradeHistoryService.getTradeById(tradeId);
  ApiResponse.success(res, data);
});

exports.createTrade = asyncHandler(async (req, res) => {
  const result = await adminTradeHistoryService.createTrade(req.body, req.admin?.id);
  ApiResponse.success(res, result, "Trade created");
});

exports.updateTrade = asyncHandler(async (req, res) => {
  const { tradeId } = req.params;
  const result = await adminTradeHistoryService.updateTrade(tradeId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "Trade updated");
});

exports.deleteTrade = asyncHandler(async (req, res) => {
  const { tradeId } = req.params;
  const result = await adminTradeHistoryService.deleteTrade(tradeId, req.admin?.id);
  ApiResponse.success(res, result, "Trade deleted");
});

exports.closeTrade = asyncHandler(async (req, res) => {
  const { tradeId } = req.params;
  const result = await adminTradeHistoryService.closeTrade(tradeId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "Trade closed");
});