/**
 * 用户权益快照 DTO
 */
import {
  UserEntitlementsSchema,
  type UserEntitlementsData,
  type UserEntitlementsInput,
} from "@/data/schemas/user/user_entitlements";

export class UserEntitlements {
  declare readonly userId: string;
  declare readonly isGuest: boolean;
  declare readonly isVip: boolean;
  declare readonly vipExpiresAt: string | null;
  declare readonly creditBalance: number;
  declare readonly dolBalance: number;
  declare readonly policy: UserEntitlementsData["policy"];
  declare readonly costs: UserEntitlementsData["costs"];
  declare readonly quotas: UserEntitlementsData["quotas"];
  declare readonly historyUnlock: UserEntitlementsData["historyUnlock"];

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

  static from(input: UserEntitlementsInput): UserEntitlements {
    return new UserEntitlements(input);
  }

  static fromJson(json: unknown): UserEntitlements {
    return UserEntitlements.from(json as UserEntitlementsInput);
  }

  toJson(): UserEntitlementsData {
    return UserEntitlementsSchema.parse(this);
  }
}
