<?php
namespace SabaiApps\Directories\Component\Payment\NotificationEvent;

class EntityDeactivatedNotificationEvent extends AbstractEntityNotificationEvent {

	protected function _notificationEntityEventInfo() {
		return array(
			'label'            => _x( 'Item deactivated', 'notification event', 'directories-pro' ) . ' - %s',
			'default_settings' => array(),
			'actions'          => array(
				'payment_expired_entities_handled',
			),
			'weight'           => 27,
		);
	}

	public function notificationEventMessages( array $settings, array $params ) {
		if ( $params[2] !== 'deactivate' ) {
			return;
		}

		return $this->_getMessageIterator( $params[1], $settings );
	}

	protected function _getDefaultNotificationLabel() {
		return sprintf(
			__( 'Your %s has been deactivated', 'directories-pro' ),
			strtolower( $singular = $this->_getContentTypeLabel() ),
			$singular
		);
	}

	protected function _getDefaultNotificationBody() {
		return array(
			sprintf(
				__( 'The following %1$s posted on our site has been deactivated.', 'directories-pro' ),
				strtolower( $singular = $this->_getContentTypeLabel() ),
				$singular
			),
			'%title%' . PHP_EOL . '%permalink_url%',
			sprintf( __( 'You can reactivate the %1$s from the dashboard page on our site.', 'directories-pro' ), strtolower( $singular ), $singular ) . PHP_EOL . '%dashboard_url%',
		);
	}

	protected function _getQueryEntitiesUrl( array $settings, $status = null, $num = 5 ) {
		return $this->_application->MainUrl(
			'/_drts/entity/' . $this->_bundleType . '/query_payment_entities',
			$this->_getQueryEntitiesParams( $settings, $status, $num ) + array( 'payment_plan' => 3 ),
			'',
			'&'
		);
	}

	public function notificationEventParams( array $settings, array $paramSettings ) {
		if ( ! $entity = $this->_application->Entity_Entity( 'post', $paramSettings['entity'] ) ) {
			throw new Exception\RuntimeException( 'Failed fetching post. ID: ' . $paramSettings['entity'] );
		}
		$params[1] = array( $entity );
		return $params;
	}
}
