<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateProductMessages extends Migration
{
    public function up()
    {
        // Product discussion messages table
        $this->forge->addField([
            'id'          => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'product_id'  => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
            'koperasi_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
            'sender_id'   => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
            'sender_name' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
            'sender_role' => ['type' => 'ENUM', 'constraint' => ['customer', 'seller', 'system'], 'default' => 'customer'],
            'message'     => ['type' => 'TEXT'],
            'product_name'=> ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'is_read'     => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0],
            'created_at'  => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey('koperasi_id');
        $this->forge->addKey('product_id');
        $this->forge->createTable('product_messages', true);
    }

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