"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findCompanyBySlug = findCompanyBySlug; exports.findCompanyByEmail = findCompanyByEmail; exports.findEmployeeByEmail = findEmployeeByEmail; exports.createCompanySignup = createCompanySignup; const prisma_1 = require("../../lib/prisma"); function findCompanyBySlug(slug) { return prisma_1.prisma.company.findUnique({ where: { slug } }); } function findCompanyByEmail(email) { return prisma_1.prisma.company.findUnique({ where: { email } }); } function findEmployeeByEmail(email) { return prisma_1.prisma.employee.findFirst({ where: { email } }); } async function createCompanySignup(db, input) { const company = await db.company.create({ data: { name: input.companyName, slug: input.slug, email: input.companyEmail, phone: input.companyPhone, address: { streetAddress: input.streetAddress, city: input.city, country: input.country, zipCode: input.zipCode, legalName: input.legalName, legalForm: input.legalForm, companyEmail: input.companyEmail, managerName: input.managerName, iceNumber: input.iceNumber, operatingLicenseNumber: input.operatingLicenseNumber, operatingLicenseIssuedAt: input.operatingLicenseIssuedAt, operatingLicenseIssuedBy: input.operatingLicenseIssuedBy, fax: input.fax || null, yearsActive: input.yearsActive, representativeName: input.representativeName || null, representativeTitle: input.representativeTitle || null, responsibleName: input.responsibleName, responsibleRole: input.responsibleRole, responsibleIdentityNumber: input.responsibleIdentityNumber, responsibleQualification: input.responsibleQualification || null, responsiblePhone: input.responsiblePhone, responsibleEmail: input.responsibleEmail, }, status: 'TRIALING', }, }); await db.brandSettings.create({ data: { companyId: company.id, displayName: input.companyName, subdomain: input.slug, publicEmail: input.companyEmail, publicPhone: input.companyPhone, publicAddress: input.streetAddress, publicCity: input.city, publicCountry: input.country, defaultLocale: input.preferredLanguage, defaultCurrency: input.currency, }, }); await db.contractSettings.create({ data: { companyId: company.id, legalName: input.legalName, registrationNumber: input.registrationNumber, taxId: input.taxId, }, }); await db.subscription.create({ data: { companyId: company.id, plan: input.plan, billingPeriod: input.billingPeriod, currency: input.currency, status: 'TRIALING', trialStartAt: input.now, trialEndAt: input.trialEndAt, currentPeriodStart: input.now, currentPeriodEnd: input.trialEndAt, }, }); const employee = await db.employee.create({ data: { companyId: company.id, clerkUserId: `local_owner_${company.id}`, firstName: input.firstName, lastName: input.lastName, email: input.ownerEmail, phone: input.companyPhone, passwordHash: input.passwordHash, role: 'OWNER', preferredLanguage: input.preferredLanguage, isActive: true, }, }); return { company, employee }; } //# sourceMappingURL=auth.company.repo.js.map