CREATE TABLE `customerInvoices` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`subscriptionId` int,
	`invoiceNumber` varchar(100) NOT NULL,
	`amountIdr` int NOT NULL,
	`status` enum('belum_dibayar','lunas','jatuh_tempo') NOT NULL DEFAULT 'belum_dibayar',
	`issuedAt` timestamp NOT NULL,
	`dueAt` timestamp NOT NULL,
	`paidAt` timestamp,
	`notes` text,
	`createdBy` int NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `customerInvoices_id` PRIMARY KEY(`id`),
	CONSTRAINT `customerInvoices_invoiceNumber_unique` UNIQUE(`invoiceNumber`)
);
--> statement-breakpoint
CREATE TABLE `customerSubscriptions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`planName` varchar(160) NOT NULL,
	`status` enum('aktif','menunggu','ditangguhkan','berhenti') NOT NULL DEFAULT 'menunggu',
	`billingCycle` enum('bulanan') NOT NULL DEFAULT 'bulanan',
	`startedAt` timestamp,
	`nextBillingDate` timestamp,
	`notes` text,
	`updatedBy` int NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `customerSubscriptions_id` PRIMARY KEY(`id`),
	CONSTRAINT `customerSubscriptions_userId_unique` UNIQUE(`userId`)
);
--> statement-breakpoint
CREATE TABLE `inventoryAuditLogs` (
	`id` int AUTO_INCREMENT NOT NULL,
	`actorId` int NOT NULL,
	`action` varchar(64) NOT NULL,
	`itemId` int,
	`transactionId` int,
	`summary` varchar(255) NOT NULL,
	`metadata` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `inventoryAuditLogs_id` PRIMARY KEY(`id`)
);
