<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateEmailTemplates extends Migration
{
    public function up()
    {
        $this->forge->addField([
            "id" => [
                "type" => "INT",
                "unsigned" => true,
                "auto_increment" => true,
            ],
            "template_key" => ["type" => "VARCHAR", "constraint" => 80],
            "name" => ["type" => "VARCHAR", "constraint" => 120],
            "description" => ["type" => "VARCHAR", "constraint" => 255],
            "category" => ["type" => "VARCHAR", "constraint" => 50],
            "subject" => ["type" => "VARCHAR", "constraint" => 255],
            "preheader" => ["type" => "VARCHAR", "constraint" => 255],
            "heading" => ["type" => "VARCHAR", "constraint" => 180],
            "body" => ["type" => "TEXT"],
            "cta_label" => [
                "type" => "VARCHAR",
                "constraint" => 80,
                "null" => true,
            ],
            "cta_url" => [
                "type" => "VARCHAR",
                "constraint" => 500,
                "null" => true,
            ],
            "accent_color" => [
                "type" => "VARCHAR",
                "constraint" => 7,
                "default" => "#ff6846",
            ],
            "enabled" => [
                "type" => "TINYINT",
                "constraint" => 1,
                "default" => 1,
            ],
            "created_at" => ["type" => "DATETIME", "null" => true],
            "updated_at" => ["type" => "DATETIME", "null" => true],
        ]);
        $this->forge->addKey("id", true);
        $this->forge->addUniqueKey("template_key");
        $this->forge->addKey("category");
        $this->forge->createTable("email_templates", true);
    }

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