type === self::TYPE_COUPON; } /** * 배열로 변환합니다. * * @return array */ public function toArray(): array { return [ 'type' => $this->type, 'coupon_id' => $this->couponId, 'code' => $this->code, 'message' => $this->message, 'context' => $this->context, ]; } /** * 배열에서 DTO를 생성합니다. * * @param array $data 배열 데이터 * @return self */ public static function fromArray(array $data): self { return new self( type: $data['type'] ?? '', couponId: $data['coupon_id'] ?? 0, code: $data['code'] ?? '', message: $data['message'] ?? '', context: $data['context'] ?? [], ); } /** * 쿠폰 만료 오류를 생성합니다. * * @param int $couponId 쿠폰 ID * @return self */ public static function couponExpired(int $couponId): self { return new self( type: self::TYPE_COUPON, couponId: $couponId, code: self::CODE_EXPIRED, message: 'sirsoft-ecommerce::messages.coupon.expired', ); } /** * 최소주문금액 미달 오류를 생성합니다. * * @param int $couponId 쿠폰 ID * @param int $minAmount 최소 주문금액 * @param int $currentAmount 현재 금액 * @return self */ public static function minAmountNotMet(int $couponId, int $minAmount, int $currentAmount): self { return new self( type: self::TYPE_COUPON, couponId: $couponId, code: self::CODE_MIN_AMOUNT, message: 'sirsoft-ecommerce::messages.coupon.min_amount_not_met', context: [ 'min_amount' => $minAmount, 'current_amount' => $currentAmount, ], ); } /** * 사용자별 쿠폰 사용 한도 초과 오류를 생성합니다. * * @param int $couponId 쿠폰 ID * @param int $limit 사용자별 사용 한도 * @param int $usedCount 현재까지 사용/적용 누적 수 * @return self */ public static function perUserLimitExceeded(int $couponId, int $limit, int $usedCount): self { return new self( type: self::TYPE_COUPON, couponId: $couponId, code: self::CODE_PER_USER_LIMIT, message: 'sirsoft-ecommerce::messages.coupon.per_user_limit_exceeded', context: [ 'limit' => $limit, 'used_count' => $usedCount, ], ); } /** * 중복할인 불가 오류를 생성합니다. * * @param int $couponId 쿠폰 ID * @return self */ public static function notCombinable(int $couponId): self { return new self( type: self::TYPE_COUPON, couponId: $couponId, code: self::CODE_NOT_COMBINABLE, message: 'sirsoft-ecommerce::messages.coupon.not_combinable', ); } /** * 적용 대상 없음 오류를 생성합니다. * * @param int $couponId 쿠폰 ID * @return self */ public static function invalidTarget(int $couponId): self { return new self( type: self::TYPE_COUPON, couponId: $couponId, code: self::CODE_INVALID_TARGET, message: 'sirsoft-ecommerce::messages.coupon.invalid_target', ); } /** * 이미 사용된 쿠폰 오류를 생성합니다. * * @param int $couponId 쿠폰 ID * @return self */ public static function alreadyUsed(int $couponId): self { return new self( type: self::TYPE_COUPON, couponId: $couponId, code: self::CODE_ALREADY_USED, message: 'sirsoft-ecommerce::messages.coupon.already_used', ); } /** * 쿠폰을 찾을 수 없음 오류를 생성합니다. * * @param int $couponId 쿠폰 ID * @return self */ public static function notFound(int $couponId): self { return new self( type: self::TYPE_COUPON, couponId: $couponId, code: self::CODE_NOT_FOUND, message: 'sirsoft-ecommerce::messages.coupon.not_found', ); } }