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

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

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

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

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

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

module.exports = ProvinceRepository;