import { PrismaClient } from '@prisma/client';
import { hashSync } from 'bcrypt';

import { data as tenants } from './dump/tenant.json';
import { data as slots } from './dump/slot.json';

async function main(prisma: PrismaClient) {
  console.log(`seed tenant data: ${tenants}`);

  await prisma.tenant.create({
    data: {
      email: tenants[0].email,
      phone: tenants[0].phone,
      username: tenants[0].username,
      password: hashSync(tenants[0].password, 10),
      first_name: tenants[0].first_name,
      last_name: tenants[0].last_name,
      Slots: {
        create: slots.map((e) => ({
          lat: e.lat,
          lng: e.lng,
          address: e.address,
          city: e.city,
          district: e.district,
          ward: e.ward,
          directions: e.directions,
          name: e.name,
          total: 5,
          empty: 0,
        })),
      },
    },
    include: {
      Slots: true,
    },
  });
}

export default main;
