/**
 * Chat wire payload fragments shared by send response and history messages.
 */
import { z } from "zod";

import {
  booleanOrFalse,
  schemaOr,
  stringOrNull,
} from "../nullable-defaults";

const CHAT_IMAGE_DEFAULTS = { type: null, url: null } as const;

const CHAT_LOCK_DETAIL_DEFAULTS = {
  locked: false,
  reason: null,
} as const;

export const ChatImageSchema = schemaOr(
  z.object({
    type: stringOrNull,
    url: stringOrNull,
  }),
  CHAT_IMAGE_DEFAULTS,
).readonly();

export const ChatLockDetailSchema = schemaOr(
  z.object({
    locked: booleanOrFalse,
    showContent: z.boolean().nullish(),
    showUpgrade: z.boolean().nullish(),
    reason: stringOrNull,
    hint: z.string().nullish(),
    actionLabel: z.string().nullish(),
    detail: z.record(z.string(), z.unknown()).nullish(),
  }),
  CHAT_LOCK_DETAIL_DEFAULTS,
).readonly();

export type ChatImageInput = z.input<typeof ChatImageSchema>;
export type ChatImageData = z.output<typeof ChatImageSchema>;
export type ChatLockDetailInput = z.input<typeof ChatLockDetailSchema>;
export type ChatLockDetailData = z.output<typeof ChatLockDetailSchema>;
