<?php
/**
 * EventTicketType Model
 *
 * @package RadiusTheme\RadiusBooking\Models
 * @since   1.2.0
 */

namespace RadiusTheme\RadiusBooking\Models;

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

use RadiusTheme\RadiusBooking\Abstracts\BaseModel;

/**
 * Class EventTicketType
 */
class EventTicketType extends BaseModel {

	protected string $table = 'radius_booking_event_ticket_types';

	protected array $fillable = array(
		'event_id',
		'name',
		'description',
		'ticket_type',
		'price',
		'capacity',
		'quantity_sold',
		'sale_start_date',
		'sale_end_date',
		'min_per_order',
		'max_per_order',
		'is_active',
		'sort_order',
	);

	protected array $casts = array(
		'event_id'      => 'integer',
		'price'         => 'float',
		'capacity'      => 'integer',
		'quantity_sold' => 'integer',
		'min_per_order' => 'integer',
		'max_per_order' => 'integer',
		'is_active'     => 'boolean',
		'sort_order'    => 'integer',
	);

	public function event() {
		return $this->belongsTo( Event::class, 'event_id' );
	}

	public function registrations() {
		return $this->hasMany( EventRegistration::class, 'ticket_type_id', 'id' );
	}

	public function get_id() {
		return $this->attributes['id'] ?? null;
	}
}
