import dotenv from 'dotenv'
import mongoose from 'mongoose'
import { User } from './models/User'
import { Photo } from './models/Photo'

dotenv.config()

mongoose.connect(process.env.MONGO_CLIENT_URL || '')

const db = mongoose.connection

export default db.once('open', async () => {
    try{
        await db.dropCollection('users')
        await db.dropCollection('photos')
    } catch(err: unknown){
        console.log(`Skipped db drop because of: ${err}`);
    }

    const [userOne, userTwo] = await User.create(
        {
            username: 'user1',
            password: 'pass'
        },
        {
            username: 'user2',
            password: 'pass',
        }
    )

    await Photo.create(
        {
            user: userOne._id,
            title: 'Darius',
            photo: 'darius.jpg'
        },
        {
            user: userOne._id,
            title: 'Aurelion Sol',
            photo: 'aurelion_sol.jpg'
        },
        {
            user: userTwo._id,
            title: 'Master Yi',
            photo: 'yi.jpg'
        },
        {
            user: userOne._id,
            title: 'Commander Ledros',
            photo: 'ledros.jpg'
        },
        {
            user: userTwo._id,
            title: 'Quinn and Valor',
            photo: 'quinn.jpg'
        },
        {
            user: userTwo._id,
            title: 'Dark start Mordekaiser',
            photo: 'dark_start_morde.jpg'
        }
    )

    db.close()
})



