const std = @import("std");
const zap = @import("zap");

pub const ws = @import("ws/root.zig");

pub const Channel = @import("Channel.zig");
pub const ChannelFrame = @import("ChannelFrame.zig");

pub fn pathGuard(r: zap.Request, endpoint_path: []const u8) error{NotFound}!void {
    if (r.path) |path| {
        if (!std.mem.eql(u8, path, endpoint_path)) {
            if (path.len >= endpoint_path.len and std.mem.eql(u8, path[0..endpoint_path.len], endpoint_path)) {
                for (1..(path.len - endpoint_path.len + 1)) |i| {
                    if (path[endpoint_path.len - 1 + i] != '/') {
                        r.setStatus(.not_found);
                        r.markAsFinished(true);
                        return error.NotFound;
                    }
                }
            } else {
                r.setStatus(.not_found);
                r.markAsFinished(true);
                return error.NotFound;
            }
        }
    } else {
        r.setStatus(.not_found);
        r.markAsFinished(true);
        return error.NotFound;
    }
}
