import { z as r } from "zod";
import { ErrorModel as i } from "./accelbyte-widgets537.mjs";
const s = "platform:youtube_id:";
class n extends Error {
}
const c = r.object({
  youtubeId: r.string(),
  as: r.string()
}), l = r.object({
  kind: r.literal("youtubeVideo"),
  value: c
});
r.union([r.string(), r.null(), i]);
const b = (e) => {
  if (r.string().safeParse(e).success) {
    if (!e.startsWith(s))
      return null;
    try {
      return decodeURIComponent(e.slice(s.length));
    } catch {
      return {
        kind: "error",
        error: new n()
      };
    }
  }
  return {
    kind: "error",
    error: new n()
  };
}, d = (e) => `${s}${encodeURIComponent(e)}`;
r.union([l, r.null(), i]);
const g = (e) => {
  if (e.imageUrl && e.as) {
    const { imageUrl: o, as: t } = e, u = b(o), a = r.string().safeParse(u);
    if (a.success && c.safeParse({
      youtubeId: u,
      as: t
    }).success)
      return u ? {
        kind: "youtubeVideo",
        value: {
          youtubeId: a.data,
          as: t || ""
        }
      } : null;
  }
  return {
    kind: "error",
    error: new n()
  };
}, p = (e) => {
  const o = l.safeParse(e);
  return o.success ? {
    as: o.data.value.as,
    caption: "-",
    height: 0,
    width: 0,
    smallImageUrl: d(o.data.value.youtubeId),
    imageUrl: d(o.data.value.youtubeId)
  } : null;
};
export {
  n as YoutubeRawMediumInvalidError,
  c as YoutubeVideoCodec,
  l as YoutubeVideoMediumCodec,
  g as fromRaw,
  p as toRaw
};
