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

/**
 * Migration 007 — Talent roster
 * stats stored as JSON: {height, bust, waist, hips, shoe, eyes, hair} etc.
 * socials stored as JSON: {instagram, tiktok, ...}
 */
class Migration_Create_talent 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' => 160),
			'name'          => array('type' => 'VARCHAR', 'constraint' => 140),
			'category'      => array('type' => 'VARCHAR', 'constraint' => 60),
			'tagline'       => array('type' => 'VARCHAR', 'constraint' => 200, 'null' => TRUE),
			'bio'           => array('type' => 'LONGTEXT', 'null' => TRUE),
			'photo'         => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'cover_photo'   => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'gallery'       => array('type' => 'LONGTEXT', 'null' => TRUE, 'comment' => 'JSON portfolio images'),
			'stats'         => array('type' => 'LONGTEXT', 'null' => TRUE, 'comment' => 'JSON measurements'),
			'socials'       => array('type' => 'LONGTEXT', 'null' => TRUE, 'comment' => 'JSON social links'),
			'location'      => array('type' => 'VARCHAR', 'constraint' => 120, 'null' => TRUE),
			'availability'  => array('type' => "ENUM('available','booked','unavailable')", 'default' => 'available'),
			'is_featured'   => array('type' => 'TINYINT', 'constraint' => 1, '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('talent', TRUE, array('ENGINE' => 'InnoDB'));

		$now = date('Y-m-d H:i:s');
		$demo = array(
			array('Ama Serwaa', 'model', 'Editorial & runway model'),
			array('Kojo Mensah', 'model', 'Commercial & fashion model'),
			array('Naa Adjeley', 'influencer', 'Lifestyle & beauty creator'),
			array('Yaw Boateng', 'photographer', 'Fashion & editorial photographer'),
			array('Esi Quartey', 'stylist', 'Creative stylist & wardrobe lead'),
			array('Akua Frimpong', 'mua', 'Editorial makeup artist'),
		);
		$order = 1;
		foreach ($demo as $d)
		{
			$slug = url_title($d[0], '-', TRUE);
			$this->db->insert('talent', array(
				'slug' => $slug, 'name' => $d[0], 'category' => $d[1],
				'tagline' => $d[2], 'bio' => $d[2].'. Represented by Bloom Iris Agency.',
				'photo' => 'talent/'.$slug.'.jpg',
				'gallery' => json_encode(array()),
				'stats' => json_encode(array()),
				'socials' => json_encode(array('instagram' => '')),
				'location' => 'Accra, Ghana', 'availability' => 'available',
				'is_featured' => ($order <= 4 ? 1 : 0),
				'sort_order' => $order++, 'is_active' => 1, 'created_at' => $now,
			));
		}
	}

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