<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateProfileViews extends Migration
{
    public function up(): void
    {
        $this->forge->addField([
            'id'              => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'viewer_user_id'  => ['type' => 'BIGINT', 'unsigned' => true],
            'viewed_user_id'  => ['type' => 'BIGINT', 'unsigned' => true],
            'created_at'      => ['type' => 'TIMESTAMP', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey(['viewed_user_id', 'created_at']);
        $this->forge->addKey(['viewer_user_id', 'viewed_user_id']);
        $this->forge->addForeignKey('viewer_user_id', 'users', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('viewed_user_id', 'users', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('profile_views', true, ['ENGINE' => 'InnoDB']);
    }

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