CREATE TABLE IF NOT EXISTS UserMembership (
    id VARCHAR(191) NOT NULL, userId VARCHAR(191) NOT NULL, planId VARCHAR(191) NOT NULL,
    startedAt DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), expiresAt DATETIME(3),
    active BOOLEAN NOT NULL DEFAULT true, createdAt DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    updatedAt DATETIME(3) NOT NULL,
    INDEX UserMembership_userId_idx(userId), PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS QuotaUsage (
    id VARCHAR(191) NOT NULL, userId VARCHAR(191) NOT NULL, quotaType VARCHAR(32) NOT NULL,
    amount INT NOT NULL, resource VARCHAR(255),
    createdAt DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    INDEX QuotaUsage_userId_quotaType_idx(userId, quotaType), INDEX QuotaUsage_createdAt_idx(createdAt), PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS CostDailySummary (
    id VARCHAR(191) NOT NULL, date DATETIME(3) NOT NULL, provider VARCHAR(32) NOT NULL,
    model VARCHAR(100), calls INT NOT NULL DEFAULT 0, tokens INT NOT NULL DEFAULT 0, cost DOUBLE NOT NULL DEFAULT 0,
    createdAt DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    UNIQUE INDEX idx_cds_date_provider_model(date, provider, model), PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
