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

/**
 * Migration 002 — Global settings (key/value store)
 * Drives contact info, social links, SEO defaults, WhatsApp, maintenance mode.
 */
class Migration_Create_settings extends CI_Migration {

	public function up()
	{
		$this->dbforge->add_field(array(
			'id'         => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE, 'auto_increment' => TRUE),
			'group'      => array('type' => 'VARCHAR', 'constraint' => 60, 'default' => 'general'),
			'key'        => array('type' => 'VARCHAR', 'constraint' => 100),
			'value'      => array('type' => 'TEXT', 'null' => TRUE),
			'type'       => array('type' => 'VARCHAR', 'constraint' => 30, 'default' => 'text'),
			'label'      => array('type' => 'VARCHAR', 'constraint' => 160, 'null' => TRUE),
		));
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_key('key');
		$this->dbforge->create_table('settings', TRUE, array('ENGINE' => 'InnoDB'));

		$now = date('Y-m-d H:i:s');
		$seed = array(
			// General
			array('general', 'site_name', 'Bloom Iris Agency', 'text', 'Site Name'),
			array('general', 'tagline', 'Creative Agency · Talent · Events · Brand Collaborations', 'text', 'Tagline'),
			array('general', 'maintenance_mode', '0', 'bool', 'Coming Soon / Maintenance Mode'),
			array('general', 'footer_text', 'Bloom Iris Agency — A creative universe of talent, campaigns and unforgettable experiences.', 'textarea', 'Footer Text'),
			// Contact
			array('contact', 'email', 'hello@bloomiris.com', 'text', 'Public Email'),
			array('contact', 'phone', '+233 (0) 593 854 493', 'text', 'Phone'),
			array('contact', 'whatsapp', '233593854493', 'text', 'WhatsApp Number (intl, no +)'),
			array('contact', 'whatsapp_message', 'Hello Bloom Iris, I would like to enquire about', 'text', 'WhatsApp Pre-filled Message'),
			array('contact', 'address', 'Accra, Ghana', 'textarea', 'Office Address'),
			array('contact', 'map_embed', '', 'textarea', 'Google Map Embed URL'),
			// Social
			array('social', 'instagram', 'https://instagram.com/bloomirisagency', 'text', 'Instagram URL'),
			array('social', 'facebook', '', 'text', 'Facebook URL'),
			array('social', 'tiktok', '', 'text', 'TikTok URL'),
			array('social', 'youtube', '', 'text', 'YouTube URL'),
			array('social', 'linkedin', '', 'text', 'LinkedIn URL'),
			array('social', 'instagram_handle', 'bloomirisagency', 'text', 'Instagram Handle (no @)'),
			// SEO
			array('seo', 'meta_description', 'Bloom Iris Agency — a creative agency in fashion, lifestyle, talent management and brand collaborations.', 'textarea', 'Meta Description'),
			array('seo', 'meta_keywords', 'creative agency, talent management, brand collaborations, fashion, Ghana', 'text', 'Meta Keywords'),
			array('seo', 'google_analytics', '', 'textarea', 'Google Analytics / Tag Code'),
			// Stats (homepage trust strip)
			array('stats', 'stat_campaigns', '120', 'text', 'Campaigns Delivered'),
			array('stats', 'stat_talent', '85', 'text', 'Talent Represented'),
			array('stats', 'stat_events', '40', 'text', 'Events Hosted'),
			array('stats', 'stat_brands', '60', 'text', 'Brand Partners'),
			// Homepage copy
			array('home', 'hero_fallback_heading', 'Where Creative Vision Blooms', 'text', 'Hero Fallback Heading'),
			array('home', 'hero_fallback_sub', 'Talent. Campaigns. Experiences. We build creative universes for brands that dare to be unforgettable.', 'textarea', 'Hero Fallback Sub-text'),
		);

		foreach ($seed as $row)
		{
			$this->db->insert('settings', array(
				'group' => $row[0], 'key' => $row[1], 'value' => $row[2],
				'type'  => $row[3], 'label' => $row[4],
			));
		}
	}

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