<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddSiteFieldsToCompaniesTable extends Migration
{
    public function up()
    {
        $this->forge->addColumn('companies', [
            'slug' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true, 'after' => 'name'],
            'is_site_enabled' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'slug'],
            'site_primary_color' => ['type' => 'VARCHAR', 'constraint' => 20, 'default' => '#1e1e2d'],
            'site_font' => ['type' => 'VARCHAR', 'constraint' => 50, 'default' => 'Tajawal'],
            'site_tagline' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'site_about_text' => ['type' => 'TEXT', 'null' => true],
            'site_vision' => ['type' => 'TEXT', 'null' => true],
            'site_mission' => ['type' => 'TEXT', 'null' => true],
            'site_services_text' => ['type' => 'TEXT', 'null' => true, 'comment' => 'وصف مختصر للخدمات المقدمة يظهر بالصفحة الرئيسية'],
            'site_footer_text' => ['type' => 'TEXT', 'null' => true],
            'site_facebook_url' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'site_twitter_url' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'site_instagram_url' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'site_whatsapp_number' => ['type' => 'VARCHAR', 'constraint' => 30, 'null' => true],
        ]);

        $this->db->query('ALTER TABLE companies ADD UNIQUE KEY companies_slug_unique (slug)');
    }

    public function down()
    {
        $this->forge->dropColumn('companies', [
            'slug', 'is_site_enabled', 'site_primary_color', 'site_font', 'site_tagline',
            'site_about_text', 'site_vision', 'site_mission', 'site_services_text', 'site_footer_text',
            'site_facebook_url', 'site_twitter_url', 'site_instagram_url', 'site_whatsapp_number',
        ]);
    }
}
