<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateHargaKhususTables extends Migration
{
    public function up(): void
    {
        // Harga khusus per produk untuk Reseller
        $this->db->query("
            CREATE TABLE IF NOT EXISTS `tb_harga_reseller` (
                `id`              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                `id_reseller`     INT UNSIGNED NOT NULL,
                `id_produk`       INT UNSIGNED NOT NULL,
                `harga_khusus`    DECIMAL(15,2) NOT NULL DEFAULT 0,
                `created_at`      DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
                `updated_at`      DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
                UNIQUE KEY `uq_reseller_produk` (`id_reseller`, `id_produk`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
        ");

        // Harga khusus per produk untuk Maklon
        $this->db->query("
            CREATE TABLE IF NOT EXISTS `tb_harga_maklon` (
                `id`              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                `id_maklon`       INT UNSIGNED NOT NULL,
                `id_produk`       INT UNSIGNED NOT NULL,
                `harga_khusus`    DECIMAL(15,2) NOT NULL DEFAULT 0,
                `created_at`      DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
                `updated_at`      DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
                UNIQUE KEY `uq_maklon_produk` (`id_maklon`, `id_produk`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
        ");
    }

    public function down(): void
    {
        $this->db->query("DROP TABLE IF EXISTS `tb_harga_reseller`");
        $this->db->query("DROP TABLE IF EXISTS `tb_harga_maklon`");
    }
}