"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteAdminFrameShape = exports.updateAdminFrameShape = exports.createAdminFrameShape = exports.getAdminFrameShapeById = exports.listAdminFrameShapes = void 0;
const frameShapeService_js_1 = require("../services/frameShapeService.js");
const apiResponse_js_1 = require("../utils/apiResponse.js");
const getStaffId = (req) => {
    if (req.auth?.actorType === "staff") {
        return req.auth.staff.id;
    }
    throw new Error("UNAUTHORIZED");
};
const listAdminFrameShapes = async (req, res) => {
    const query = req.validatedQuery;
    const result = await (0, frameShapeService_js_1.listFrameShapes)(query);
    return (0, apiResponse_js_1.sendSuccess)(res, 200, result);
};
exports.listAdminFrameShapes = listAdminFrameShapes;
const getAdminFrameShapeById = async (req, res) => {
    const { id } = req.validatedParams;
    const frameShape = await (0, frameShapeService_js_1.getFrameShapeById)(id);
    if (!frameShape) {
        return (0, apiResponse_js_1.sendError)(res, 404, "FRAME_SHAPE_NOT_FOUND", "Frame shape not found.");
    }
    return (0, apiResponse_js_1.sendSuccess)(res, 200, frameShape);
};
exports.getAdminFrameShapeById = getAdminFrameShapeById;
const createAdminFrameShape = async (req, res) => {
    const input = req.validatedBody;
    const staffId = getStaffId(req);
    try {
        const frameShape = await (0, frameShapeService_js_1.createFrameShape)(input, staffId);
        return (0, apiResponse_js_1.sendSuccess)(res, 201, frameShape, "Frame shape created.");
    }
    catch (error) {
        if (error.message === "FRAME_SHAPE_NOT_FOUND") {
            return (0, apiResponse_js_1.sendError)(res, 404, "FRAME_SHAPE_NOT_FOUND", "Frame shape not found.");
        }
        throw error;
    }
};
exports.createAdminFrameShape = createAdminFrameShape;
const updateAdminFrameShape = async (req, res) => {
    const { id } = req.validatedParams;
    const input = req.validatedBody;
    const staffId = getStaffId(req);
    try {
        const frameShape = await (0, frameShapeService_js_1.updateFrameShape)(id, input, staffId);
        return (0, apiResponse_js_1.sendSuccess)(res, 200, frameShape, "Frame shape updated.");
    }
    catch (error) {
        if (error.message === "FRAME_SHAPE_NOT_FOUND") {
            return (0, apiResponse_js_1.sendError)(res, 404, "FRAME_SHAPE_NOT_FOUND", "Frame shape not found.");
        }
        throw error;
    }
};
exports.updateAdminFrameShape = updateAdminFrameShape;
const deleteAdminFrameShape = async (req, res) => {
    const { id } = req.validatedParams;
    try {
        await (0, frameShapeService_js_1.deleteFrameShape)(id);
        return (0, apiResponse_js_1.sendSuccess)(res, 200, null, "Frame shape deleted.");
    }
    catch (error) {
        if (error.message === "FRAME_SHAPE_NOT_FOUND") {
            return (0, apiResponse_js_1.sendError)(res, 404, "FRAME_SHAPE_NOT_FOUND", "Frame shape not found.");
        }
        throw error;
    }
};
exports.deleteAdminFrameShape = deleteAdminFrameShape;
//# sourceMappingURL=frameShapeController.js.map