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

/**
 * Migration 006 — Events / activations
 * is_paid + ticket_price drive Paystack ticketing for paid events.
 */
class Migration_Create_events extends CI_Migration {

	public function up()
	{
		$this->dbforge->add_field(array(
			'id'            => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE, 'auto_increment' => TRUE),
			'slug'          => array('type' => 'VARCHAR', 'constraint' => 180),
			'title'         => array('type' => 'VARCHAR', 'constraint' => 180),
			'event_type'    => array('type' => 'VARCHAR', 'constraint' => 60),
			'cover_image'   => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'excerpt'       => array('type' => 'TEXT', 'null' => TRUE),
			'description'   => array('type' => 'LONGTEXT', 'null' => TRUE),
			'event_date'    => array('type' => 'DATE', 'null' => TRUE),
			'event_time'    => array('type' => 'VARCHAR', 'constraint' => 60, 'null' => TRUE),
			'location'      => array('type' => 'VARCHAR', 'constraint' => 200, 'null' => TRUE),
			'gallery'       => array('type' => 'LONGTEXT', 'null' => TRUE, 'comment' => 'JSON recap images'),
			'partners'      => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'allow_rsvp'    => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 1),
			'is_paid'       => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 0),
			'ticket_price'  => array('type' => 'DECIMAL', 'constraint' => '10,2', 'default' => 0.00),
			'capacity'      => array('type' => 'INT', 'constraint' => 6, 'null' => TRUE),
			'is_featured'   => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 0),
			'meta_title'    => array('type' => 'VARCHAR', 'constraint' => 200, 'null' => TRUE),
			'meta_desc'     => array('type' => 'VARCHAR', 'constraint' => 300, 'null' => TRUE),
			'is_active'     => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 1),
			'created_at'    => array('type' => 'DATETIME', 'null' => TRUE),
			'updated_at'    => array('type' => 'DATETIME', 'null' => TRUE),
		));
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_key('slug');
		$this->dbforge->create_table('events', TRUE, array('ENGINE' => 'InnoDB'));

		// RSVPs table
		$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' => 120),
			'email'      => array('type' => 'VARCHAR', 'constraint' => 160),
			'phone'      => array('type' => 'VARCHAR', 'constraint' => 30, 'null' => TRUE),
			'guests'     => array('type' => 'INT', 'constraint' => 3, 'default' => 1),
			'created_at' => array('type' => 'DATETIME', 'null' => TRUE),
		));
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_key('event_id');
		$this->dbforge->create_table('event_rsvps', TRUE, array('ENGINE' => 'InnoDB'));

		$now = date('Y-m-d H:i:s');
		$this->db->insert_batch('events', array(
			array(
				'slug' => 'bloom-iris-spring-showcase', 'title' => 'Bloom Iris Spring Showcase',
				'event_type' => 'fashion-event', 'cover_image' => 'events/spring-showcase.jpg',
				'excerpt' => 'An evening celebrating the season\'s boldest creative work.',
				'description' => 'Join us for an unforgettable evening of fashion, talent and creative collaboration.',
				'event_date' => date('Y-m-d', strtotime('+45 days')), 'event_time' => '6:00 PM',
				'location' => 'Accra, Ghana', 'allow_rsvp' => 1, 'is_paid' => 0,
				'is_featured' => 1, 'is_active' => 1, 'created_at' => $now,
			),
			array(
				'slug' => 'iris-pop-up-experience', 'title' => 'Iris Pop-Up Experience',
				'event_type' => 'pop-up', 'cover_image' => 'events/pop-up.jpg',
				'excerpt' => 'A curated pop-up bringing the Bloom Iris universe to life.',
				'description' => 'A limited pop-up experience featuring talent, styling and brand activations.',
				'event_date' => date('Y-m-d', strtotime('-30 days')), 'event_time' => '12:00 PM',
				'location' => 'Accra, Ghana', 'allow_rsvp' => 0, 'is_paid' => 0,
				'is_featured' => 0, 'is_active' => 1, 'created_at' => $now,
			),
		));
	}

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