<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateBrandSquareAdmin extends Migration
{
    public function up()
    {
        $this->forge->addField([
            "id" => [
                "type" => "INT",
                "unsigned" => true,
                "auto_increment" => true,
            ],
            "name" => ["type" => "VARCHAR", "constraint" => 100],
            "email" => ["type" => "VARCHAR", "constraint" => 190],
            "password_hash" => ["type" => "VARCHAR", "constraint" => 255],
            "last_login_at" => ["type" => "DATETIME", "null" => true],
            "created_at" => ["type" => "DATETIME", "null" => true],
            "updated_at" => ["type" => "DATETIME", "null" => true],
        ]);
        $this->forge->addKey("id", true);
        $this->forge->addUniqueKey("email");
        $this->forge->createTable("admin_users", true);

        $this->forge->addField([
            "id" => [
                "type" => "INT",
                "unsigned" => true,
                "auto_increment" => true,
            ],
            "business_name" => ["type" => "VARCHAR", "constraint" => 150],
            "industry" => ["type" => "VARCHAR", "constraint" => 120],
            "message" => ["type" => "TEXT", "null" => true],
            "style" => [
                "type" => "VARCHAR",
                "constraint" => 50,
                "null" => true,
            ],
            "budget" => [
                "type" => "VARCHAR",
                "constraint" => 50,
                "null" => true,
            ],
            "name" => ["type" => "VARCHAR", "constraint" => 120],
            "email" => ["type" => "VARCHAR", "constraint" => 190],
            "phone" => [
                "type" => "VARCHAR",
                "constraint" => 40,
                "null" => true,
            ],
            "source" => [
                "type" => "VARCHAR",
                "constraint" => 50,
                "default" => "home",
            ],
            "status" => [
                "type" => "VARCHAR",
                "constraint" => 30,
                "default" => "new",
            ],
            "ip_address" => [
                "type" => "VARCHAR",
                "constraint" => 45,
                "null" => true,
            ],
            "user_agent" => [
                "type" => "VARCHAR",
                "constraint" => 255,
                "null" => true,
            ],
            "created_at" => ["type" => "DATETIME", "null" => true],
            "updated_at" => ["type" => "DATETIME", "null" => true],
        ]);
        $this->forge->addKey("id", true);
        $this->forge->addKey("status");
        $this->forge->addKey("created_at");
        $this->forge->createTable("leads", true);

        $this->forge->addField([
            "id" => [
                "type" => "INT",
                "unsigned" => true,
                "auto_increment" => true,
            ],
            "setting_key" => ["type" => "VARCHAR", "constraint" => 120],
            "setting_value" => ["type" => "TEXT", "null" => true],
            "is_secret" => [
                "type" => "TINYINT",
                "constraint" => 1,
                "default" => 0,
            ],
            "created_at" => ["type" => "DATETIME", "null" => true],
            "updated_at" => ["type" => "DATETIME", "null" => true],
        ]);
        $this->forge->addKey("id", true);
        $this->forge->addUniqueKey("setting_key");
        $this->forge->createTable("settings", true);
    }

    public function down()
    {
        $this->forge->dropTable("settings", true);
        $this->forge->dropTable("leads", true);
        $this->forge->dropTable("admin_users", true);
    }
}
