<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20260715100324 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create inventory tables: items, packages and package items (per-tenant).';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE inventory_items (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, entity_type VARCHAR(20) NOT NULL, entity_id INT NOT NULL, name VARCHAR(120) NOT NULL, consumable VARCHAR(120) DEFAULT NULL, unit VARCHAR(30) NOT NULL, price INT NOT NULL, stock INT NOT NULL, alert_threshold INT NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, UNIQUE INDEX UNIQ_3D82424DD17F50A6 (uuid), INDEX idx_inventory_items_owner (entity_type, entity_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE inventory_package_items (id INT AUTO_INCREMENT NOT NULL, amount INT NOT NULL, package_id INT NOT NULL, item_id INT NOT NULL, INDEX IDX_17172D5EF44CABFF (package_id), INDEX IDX_17172D5E126F525E (item_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE inventory_packages (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, entity_type VARCHAR(20) NOT NULL, entity_id INT NOT NULL, title VARCHAR(120) NOT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, UNIQUE INDEX UNIQ_2FFF7A36D17F50A6 (uuid), INDEX idx_inventory_packages_owner (entity_type, entity_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE inventory_package_items ADD CONSTRAINT FK_17172D5EF44CABFF FOREIGN KEY (package_id) REFERENCES inventory_packages (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE inventory_package_items ADD CONSTRAINT FK_17172D5E126F525E FOREIGN KEY (item_id) REFERENCES inventory_items (id) ON DELETE CASCADE');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE inventory_package_items DROP FOREIGN KEY FK_17172D5EF44CABFF');
        $this->addSql('ALTER TABLE inventory_package_items DROP FOREIGN KEY FK_17172D5E126F525E');
        $this->addSql('DROP TABLE inventory_items');
        $this->addSql('DROP TABLE inventory_package_items');
        $this->addSql('DROP TABLE inventory_packages');
    }
}
