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

/**
 * Migration 005 — Portfolio / campaigns showcase
 * Case study structure: Brief -> Concept -> Execution -> Results
 * gallery + reel_video stored as JSON / path. talent_ids = comma list.
 */
class Migration_Create_portfolio 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),
			'category'      => array('type' => 'VARCHAR', 'constraint' => 60),
			'brand'         => array('type' => 'VARCHAR', 'constraint' => 120, 'null' => TRUE),
			'year'          => array('type' => 'VARCHAR', 'constraint' => 4, 'null' => TRUE),
			'cover_image'   => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'excerpt'       => array('type' => 'TEXT', 'null' => TRUE),
			'cs_brief'      => array('type' => 'TEXT', 'null' => TRUE),
			'cs_concept'    => array('type' => 'TEXT', 'null' => TRUE),
			'cs_execution'  => array('type' => 'TEXT', 'null' => TRUE),
			'cs_results'    => array('type' => 'TEXT', 'null' => TRUE),
			'gallery'       => array('type' => 'LONGTEXT', 'null' => TRUE, 'comment' => 'JSON image array'),
			'video_type'    => array('type' => "ENUM('none','file','youtube')", 'default' => 'none'),
			'video_file'    => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'youtube_id'    => array('type' => 'VARCHAR', 'constraint' => 40, 'null' => TRUE),
			'talent_ids'    => array('type' => 'VARCHAR', 'constraint' => 255, '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),
			'views'         => array('type' => 'INT', 'constraint' => 8, 'default' => 0),
			'sort_order'    => array('type' => 'INT', 'constraint' => 5, 'default' => 0),
			'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->add_key('category');
		$this->dbforge->create_table('portfolio', TRUE, array('ENGINE' => 'InnoDB'));

		$now = date('Y-m-d H:i:s');
		$demo = array(
			array('Aurora Fashion Week Campaign', 'fashion-campaigns', 'Aurora Couture', '2026'),
			array('Velvet Bloom Editorial', 'editorial-shoots', 'Velvet Studios', '2026'),
			array('Sunset Pop-Up Activation', 'events-activations', 'Lumen Beverages', '2025'),
			array('Cityscape Brand Collaboration', 'brand-collaborations', 'Metro Apparel', '2025'),
			array('Behind the Lens — Spring', 'behind-the-scenes', 'Bloom Iris', '2026'),
			array('Motion Reel — Iris Vol.1', 'video-reels', 'Bloom Iris', '2026'),
		);
		$order = 1;
		foreach ($demo as $d)
		{
			$slug = url_title($d[0], '-', TRUE);
			$this->db->insert('portfolio', array(
				'slug' => $slug, 'title' => $d[0], 'category' => $d[1],
				'brand' => $d[2], 'year' => $d[3],
				'cover_image' => 'portfolio/'.$slug.'.jpg',
				'excerpt' => 'A creative project delivered by Bloom Iris Agency.',
				'cs_brief' => 'The brand approached Bloom Iris with a clear ambition and a tight timeline.',
				'cs_concept' => 'We developed an editorial creative direction rooted in the brand identity.',
				'cs_execution' => 'Talent, styling, location and crew were assembled and the shoot executed.',
				'cs_results' => 'The campaign delivered strong engagement and a refreshed brand presence.',
				'gallery' => json_encode(array()),
				'is_featured' => ($order <= 3 ? 1 : 0),
				'sort_order' => $order++, 'is_active' => 1, 'created_at' => $now,
			));
		}
	}

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