-- ================================================================
-- Everest MySQL Schema
-- JSON'dan MySQL'e geçişte bu script çalıştırılır.
-- Admin panelindeki Veritabanı sayfası bunu otomatik yapar.
-- ================================================================

CREATE TABLE IF NOT EXISTS `products` (
    `id`           VARCHAR(64)    NOT NULL PRIMARY KEY,
    `name`         VARCHAR(512)   NOT NULL DEFAULT '',
    `slug`         VARCHAR(512)   UNIQUE DEFAULT NULL,
    `description`  TEXT           DEFAULT NULL,
    `price`        DECIMAL(12,2)  DEFAULT 0.00,
    `currency`     VARCHAR(10)    DEFAULT 'TRY',
    `stock`        INT            DEFAULT 0,
    `categories`   JSON           DEFAULT NULL,
    `images`       JSON           DEFAULT NULL,
    `image`        VARCHAR(512)   DEFAULT NULL,
    `brand`        VARCHAR(255)   DEFAULT NULL,
    `brand_slug`   VARCHAR(255)   DEFAULT NULL,
    `model`        VARCHAR(255)   DEFAULT NULL,
    `featured`     TINYINT(1)     DEFAULT 0,
    `active`       TINYINT(1)     DEFAULT 1,
    `specs`        JSON           DEFAULT NULL,
    `tags`         JSON           DEFAULT NULL,
    `created_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP,
    `updated_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `categories` (
    `id`           VARCHAR(64)    NOT NULL PRIMARY KEY,
    `name`         VARCHAR(255)   NOT NULL DEFAULT '',
    `slug`         VARCHAR(255)   UNIQUE NOT NULL,
    `parent_slug`  VARCHAR(255)   DEFAULT NULL,
    `image`        VARCHAR(512)   DEFAULT NULL,
    `sort_order`   INT            DEFAULT 0,
    `active`       TINYINT(1)     DEFAULT 1,
    `created_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `orders` (
    `id`           VARCHAR(64)    NOT NULL PRIMARY KEY,
    `user_id`      VARCHAR(64)    DEFAULT NULL,
    `customer`     JSON           DEFAULT NULL,
    `items`        JSON           DEFAULT NULL,
    `total`        DECIMAL(12,2)  DEFAULT 0.00,
    `currency`     VARCHAR(10)    DEFAULT 'TRY',
    `status`       VARCHAR(64)    DEFAULT 'pending',
    `note`         TEXT           DEFAULT NULL,
    `receipt_file` VARCHAR(512)   DEFAULT NULL,
    `created_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP,
    `updated_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `users` (
    `id`           VARCHAR(64)    NOT NULL PRIMARY KEY,
    `name`         VARCHAR(255)   DEFAULT '',
    `email`        VARCHAR(255)   UNIQUE DEFAULT NULL,
    `password`     VARCHAR(512)   DEFAULT NULL,
    `role`         VARCHAR(64)    DEFAULT 'customer',
    `avatar`       VARCHAR(512)   DEFAULT NULL,
    `google_id`    VARCHAR(255)   DEFAULT NULL,
    `active`       TINYINT(1)     DEFAULT 1,
    `created_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `pages` (
    `id`           VARCHAR(64)    NOT NULL PRIMARY KEY,
    `title`        VARCHAR(512)   DEFAULT '',
    `slug`         VARCHAR(512)   UNIQUE DEFAULT NULL,
    `content`      LONGTEXT       DEFAULT NULL,
    `active`       TINYINT(1)     DEFAULT 1,
    `created_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `tenants` (
    `id`           VARCHAR(64)    NOT NULL PRIMARY KEY,
    `name`         VARCHAR(255)   DEFAULT '',
    `domain`       VARCHAR(255)   DEFAULT NULL,
    `active`       TINYINT(1)     DEFAULT 1,
    `created_at`   DATETIME       DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
