"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KyselySSOConfigRepository = void 0; const SSOConfig_1 = require("../../domain/entities/SSOConfig"); const UniqueId_1 = require("../../../../shared/domain/UniqueId"); class KyselySSOConfigRepository { constructor(db) { this.db = db; } async save(config) { await this.db .insertInto('sso_configs') .values({ id: config.id.toString(), organization_id: config.organizationId, provider: config.provider, enabled: config.enabled ? 1 : 0, config_json: JSON.stringify(config.config), created_at: config.createdAt.getTime(), }) .onConflict((oc) => oc.column('id').doUpdateSet({ enabled: config.enabled ? 1 : 0, config_json: JSON.stringify(config.config), })) .execute(); } async findByOrganizationId(organizationId) { const row = await this.db .selectFrom('sso_configs') .selectAll() .where('organization_id', '=', organizationId) .executeTakeFirst(); return row ? this.toDomain(row) : null; } async findById(id) { const row = await this.db .selectFrom('sso_configs') .selectAll() .where('id', '=', id) .executeTakeFirst(); return row ? this.toDomain(row) : null; } toDomain(row) { return SSOConfig_1.SSOConfig.reconstitute({ organizationId: row.organization_id, provider: row.provider, enabled: row.enabled === 1, config: JSON.parse(row.config_json), createdAt: new Date(row.created_at), }, UniqueId_1.UniqueId.from(row.id)); } } exports.KyselySSOConfigRepository = KyselySSOConfigRepository;