/**
 * 私密消息解锁响应 DTO
 */
import {
  UnlockPrivateResponseSchema,
  type UnlockPrivateReason,
  type UnlockPrivateResponseData,
  type UnlockPrivateResponseInput,
} from "@/data/schemas/chat/unlock_private_response";

export class UnlockPrivateResponse {
  declare readonly unlocked: boolean;
  declare readonly content: string | null;
  declare readonly showUpgrade: boolean;
  declare readonly paywallTriggered: boolean;
  declare readonly privateFreeLimit: number;
  declare readonly privateUsedToday: number;
  declare readonly reason: UnlockPrivateReason;

  private constructor(input: UnlockPrivateResponseInput) {
    const data = UnlockPrivateResponseSchema.parse(input);
    Object.assign(this, data);
    Object.freeze(this);
  }

  static from(input: UnlockPrivateResponseInput): UnlockPrivateResponse {
    return new UnlockPrivateResponse(input);
  }

  static fromJson(json: unknown): UnlockPrivateResponse {
    return UnlockPrivateResponse.from(json as UnlockPrivateResponseInput);
  }

  toJson(): UnlockPrivateResponseData {
    return UnlockPrivateResponseSchema.parse(this);
  }
}
