"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv/config");
const prisma_service_1 = require("../src/prisma/prisma.service");
const argon = __importStar(require("@node-rs/argon2"));
const prisma = new prisma_service_1.PrismaService();
function randomBetween(min, max) {
    return Math.random() * (max - min) + min;
}
function randomInt(min, max) {
    return Math.floor(randomBetween(min, max + 1));
}
function pick(arr) {
    return arr[Math.floor(Math.random() * arr.length)];
}
const firstNames = [
    "Agus", "Budi", "Made", "Putu", "Ketut", "Wayan",
    "Sari", "Dewi", "Putri", "Ayu",
    "Rudi", "Joko", "Indra", "Rina", "Dian"
];
const lastNames = [
    "Saputra", "Wijaya", "Santoso", "Pratama",
    "Utama", "Mahendra", "Putra", "Suryadi"
];
const streets = [
    "Melati", "Kenanga", "Anggrek", "Mawar",
    "Cempaka", "Sudirman", "Diponegoro"
];
function generateName() {
    return `${pick(firstNames)} ${pick(lastNames)}`;
}
function generatePhone() {
    return `08${randomInt(1000000000, 9999999999)}`;
}
function generateKTP() {
    return String(randomInt(1000000000000000, 9999999999999999));
}
function generateAddress() {
    return `Jl. ${pick(streets)} No ${randomInt(1, 200)}`;
}
function generateBankAccountNo() {
    return String(randomInt(1000000000, 9999999999));
}
async function sanitizeCustomers() {
    console.log("Sanitizing customers...");
    const customers = await prisma.customer.findMany({
        select: { id: true }
    });
    for (const c of customers) {
        await prisma.customer.update({
            where: { id: c.id },
            data: {
                fullName: generateName(),
                phoneNumber: generatePhone(),
                ktpNumber: Math.random() > 0.3 ? generateKTP() : null,
                ktpPhotoUrl: null,
                address: generateAddress(),
            }
        });
    }
    console.log(`Sanitized ${customers.length} customers`);
}
async function sanitizeTransactions() {
    console.log("Sanitizing transactions...");
    const transactions = await prisma.transaction.findMany({
        select: { id: true }
    });
    for (const trx of transactions) {
        await prisma.transaction.update({
            where: { id: trx.id },
            data: {
                bankAccountNo: generateBankAccountNo(),
                bankAccountName: generateName(),
            }
        });
    }
    console.log(`Sanitized ${transactions.length} transactions`);
}
async function sanitizeUsers() {
    console.log("Resetting user passwords...");
    const DEFAULT_PASSWORD = "password123";
    const hashedPassword = await argon.hash(DEFAULT_PASSWORD);
    const users = await prisma.user.findMany({
        select: { id: true }
    });
    for (const u of users) {
        await prisma.user.update({
            where: { id: u.id },
            data: {
                hash: hashedPassword,
            }
        });
    }
    console.log(`Reset ${users.length} user passwords`);
    console.log(`Default password: ${DEFAULT_PASSWORD}`);
}
async function main() {
    console.log("Starting data sanitization...");
    await sanitizeCustomers();
    await sanitizeTransactions();
    await sanitizeUsers();
    console.log("Sanitization complete ✅");
}
main()
    .catch(console.error)
    .finally(async () => {
    await prisma.$disconnect();
});
//# sourceMappingURL=sanitize-data.js.map