<?php
namespace WPEventGenius\Common\Registration\Field;
use WPEventGenius\Common\Registration\Submission\Validator;

if ( ! defined( 'ABSPATH' ) ) {
	exit; 
}

class CheckboxType extends BaseFieldType {
	public function get_type() {
		return 'checkbox';
	}

	public function get_value( $registration_data = array() ) {
		$slug = $this->get_slug();
		if ( ! array_key_exists( $slug, $registration_data ) ) {
			return array();
		}
		$stored = $registration_data[ $slug ];
		if ( Validator::is_absent_submission_value( $stored ) ) {
			return array();
		}
		if ( is_string( $stored ) ) {
			return array( $stored );
		}
		return $stored;
	}

	public function is_valid( Validator $validator, $value ) {
		return $validator->checkbox( $value );
	}
}