const prisma = require('../../prisma/PrismaClient.js');

const CityRepository = {
    findAll: async ({ skip, take, where, orderBy }) => {
        return prisma.city.findMany({
            where,
            skip,
            take,
            orderBy,
            select: {
                id: true,
                name: true,
                // province_id: true,
                createdAt: true,
                updatedAt: true,
                province: {
                    select: {
                        id: true,
                        name: true
                    }
                }
            },
        });
    },

    countAll: async (where) => {
        return prisma.city.count({ where });
    },

    findById: async (id) => {
        return prisma.city.findFirst({
            where: {
                id,
                deletedAt: null
            },
            select: {
                id: true,
                name: true,
                createdAt: true,
                updatedAt: true,
                province: {
                    select: {
                        id: true,
                        name: true
                    }
                }
            }
        });
    },

    create: async (data) => {
        return prisma.city.create({ data });
    },

    update: async (id, data) => {
        return prisma.city.update({
            where: { id },
            data
        });
    },
};

module.exports = CityRepository;