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

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

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

const CHAT_LOCK_DETAIL_DEFAULTS = {
  locked: false,
  showContent: true,
  showUpgrade: false,
  reason: null,
  hint: null,
  detail: null,
} as const;

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

export const ChatLockDetailSchema = schemaOr(
  z.object({
    locked: booleanOrFalse,
    showContent: booleanOrTrue,
    showUpgrade: booleanOrFalse,
    reason: stringOrNull,
    hint: stringOrNull,
    detail: unknownRecordOrNull,
  }),
  CHAT_LOCK_DETAIL_DEFAULTS,
);

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>;
