export type UserPropertiesJson = { phone_number?: string; email_address?: string; marketing_notification_consent?: boolean; marketing_notification_sms_consent?: boolean; marketing_notification_email_consent?: boolean; marketing_notification_push_consent?: boolean; marketing_notification_kakao_consent?: boolean; nighttime_notification_consent?: boolean; is_all_notification_blocked?: boolean; age?: number; gender?: 'male' | 'female'; }; export class UserProperties { constructor( public phone_number?: string, public email_address?: string, public marketing_notification_consent?: boolean, public marketing_notification_sms_consent?: boolean, public marketing_notification_email_consent?: boolean, public marketing_notification_push_consent?: boolean, public marketing_notification_kakao_consent?: boolean, public nighttime_notification_consent?: boolean, public is_all_notification_blocked?: boolean, public age?: number, public gender?: 'male' | 'female' ) {} static from(input: unknown): UserProperties | null { if (!input || typeof input !== 'object' || Array.isArray(input)) { return null; } const typedInput = input as Record; const getString = (k: keyof UserPropertiesJson) => typeof typedInput[k] === 'string' ? (typedInput[k] as string) : undefined; const getBoolean = (k: keyof UserPropertiesJson) => typeof typedInput[k] === 'boolean' ? (typedInput[k] as boolean) : undefined; const getNumber = (k: keyof UserPropertiesJson) => typeof typedInput[k] === 'number' ? (typedInput[k] as number) : undefined; const getGender = (k: keyof UserPropertiesJson) => { const value = typedInput[k]; return value === 'male' || value === 'female' ? value : undefined; }; return new UserProperties( getString('phone_number'), getString('email_address'), getBoolean('marketing_notification_consent'), getBoolean('marketing_notification_sms_consent'), getBoolean('marketing_notification_email_consent'), getBoolean('marketing_notification_push_consent'), getBoolean('marketing_notification_kakao_consent'), getBoolean('nighttime_notification_consent'), getBoolean('is_all_notification_blocked'), getNumber('age'), getGender('gender') ); } toJson(): UserPropertiesJson { const original: UserPropertiesJson = { phone_number: this.phone_number, email_address: this.email_address, marketing_notification_consent: this.marketing_notification_consent, marketing_notification_sms_consent: this.marketing_notification_sms_consent, marketing_notification_email_consent: this.marketing_notification_email_consent, marketing_notification_push_consent: this.marketing_notification_push_consent, marketing_notification_kakao_consent: this.marketing_notification_kakao_consent, nighttime_notification_consent: this.nighttime_notification_consent, is_all_notification_blocked: this.is_all_notification_blocked, age: this.age, gender: this.gender, }; const sanitized = Object.fromEntries( Object.entries(original).filter(([, v]) => v != null) ) as UserPropertiesJson; return sanitized; } }