import { z } from "zod";

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

export const PrivateAlbumImageSchema = z
  .object({
    url: stringOrEmpty,
    locked: booleanOrFalse,
    index: numberOrZero,
  })
  .readonly();

export const PrivateAlbumLockDetailSchema = z
  .object({
    locked: booleanOrFalse,
  })
  .readonly();

export const PrivateAlbumSchema = z
  .object({
    albumId: stringOrEmpty,
    title: stringOrEmpty,
    content: stringOrNull,
    previewText: stringOrEmpty,
    imageCount: numberOrZero,
    images: arrayOrEmpty(PrivateAlbumImageSchema),
    locked: booleanOrFalse,
    unlocked: booleanOrFalse,
    unlockCost: numberOrZero,
    publishedAt: stringOrNull,
    lockDetail: schemaOr(PrivateAlbumLockDetailSchema, { locked: false }),
  })
  .readonly();

export type PrivateAlbumImageData = z.output<typeof PrivateAlbumImageSchema>;
export type PrivateAlbumInput = z.input<typeof PrivateAlbumSchema>;
export type PrivateAlbumData = z.output<typeof PrivateAlbumSchema>;

export type PrivateAlbum = PrivateAlbumData;
