import UserMiddleware from "../Middleware/UserAuthorization";
import WorkspaceNotificationSummaryService from "../Services/WorkspaceNotificationSummaryService";
import Response from "../Utils/Response";
import BaseAPI from "./BaseAPI";
import CommonAPI from "./CommonAPI";
import WorkspaceNotificationSummary from "../../Models/DatabaseModels/WorkspaceNotificationSummary";
import ObjectID from "../../Types/ObjectID";
import BadDataException from "../../Types/Exception/BadDataException";
export default class WorkspaceNotificationSummaryAPI extends BaseAPI {
    constructor() {
        var _a;
        super(WorkspaceNotificationSummary, WorkspaceNotificationSummaryService);
        this.router.post(`${(_a = new this.entityType().getCrudApiPath()) === null || _a === void 0 ? void 0 : _a.toString()}/test/:workspaceNotificationSummaryId`, UserMiddleware.getUserMiddleware, async (req, res, next) => {
            try {
                const databaseProps = await CommonAPI.getDatabaseCommonInteractionProps(req);
                const summaryId = new ObjectID(req.params["workspaceNotificationSummaryId"]);
                // Verify the summary belongs to the user's project
                const summary = await this.service.findOneById({
                    id: summaryId,
                    select: { projectId: true },
                    props: databaseProps,
                });
                if (!summary) {
                    return Response.sendErrorResponse(req, res, new BadDataException("Summary not found or access denied"));
                }
                await this.service.testSummary({
                    summaryId: summaryId,
                    props: databaseProps,
                    projectId: databaseProps.tenantId,
                    testByUserId: databaseProps.userId,
                });
                return Response.sendEmptySuccessResponse(req, res);
            }
            catch (e) {
                next(e);
            }
        });
    }
}
//# sourceMappingURL=WorkspaceNotificationSummaryAPI.js.map