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

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

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

exports.getAssetById = asyncHandler(async (req, res) => {
  const { assetId } = req.params;
  const data = await adminAssetService.getAssetById(assetId);
  ApiResponse.success(res, data);
});

exports.createAsset = asyncHandler(async (req, res) => {
  const asset = await adminAssetService.createAsset(req.body, req.file?.filename ?? undefined, req.admin?.id);
  ApiResponse.success(res, { asset }, "Asset created successfully");
});

exports.updateAsset = asyncHandler(async (req, res) => {
  const { assetId } = req.params;
  const asset = await adminAssetService.updateAsset(assetId, req.body,req.file?.filename ?? undefined, req.admin?.id);
  ApiResponse.success(res, { asset }, "Asset updated successfully");
});

exports.deleteAsset = asyncHandler(async (req, res) => {
  const { assetId } = req.params;
  const result = await adminAssetService.deleteAsset(assetId, req.admin?.id);
  ApiResponse.success(res, result, "Asset deleted successfully");
});