import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js";

export const lastSales = async (date: string) => {
    const { data, error } = (await tryCatch(
        query(lastSalesPriceCheck.replace("[date]", date), "Last sales price")
    )) as any;

    if (error) {
        return {
            success: false,
            message: "Error getting the last sales price",
            data: error,
        };
    }

    return {
        success: true,
        message: `Last sales price for all av in the last 5 years`,
        data: data.data,
    };
};
