<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Migration 016 — Event tickets (Paystack)
 * payment_status: pending -> paid / failed. reference = Paystack reference.
 */
class Migration_Create_event_tickets extends CI_Migration {

	public function up()
	{
		$this->dbforge->add_field(array(
			'id'             => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE, 'auto_increment' => TRUE),
			'event_id'       => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE),
			'name'           => array('type' => 'VARCHAR', 'constraint' => 140),
			'email'          => array('type' => 'VARCHAR', 'constraint' => 160),
			'phone'          => array('type' => 'VARCHAR', 'constraint' => 30, 'null' => TRUE),
			'quantity'       => array('type' => 'INT', 'constraint' => 3, 'default' => 1),
			'amount'         => array('type' => 'DECIMAL', 'constraint' => '10,2', 'default' => 0.00),
			'reference'      => array('type' => 'VARCHAR', 'constraint' => 100, 'null' => TRUE),
			'ticket_code'    => array('type' => 'VARCHAR', 'constraint' => 40, 'null' => TRUE),
			'payment_status' => array('type' => "ENUM('pending','paid','failed')", 'default' => 'pending'),
			'checked_in'     => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 0),
			'created_at'     => array('type' => 'DATETIME', 'null' => TRUE),
			'updated_at'     => array('type' => 'DATETIME', 'null' => TRUE),
		));
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_key('event_id');
		$this->dbforge->add_key('reference');
		$this->dbforge->create_table('event_tickets', TRUE, array('ENGINE' => 'InnoDB'));
	}

	public function down()
	{
		$this->dbforge->drop_table('event_tickets', TRUE);
	}
}
