"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetOrganizationLoginUrlQueryHandler = void 0;
const Logger_1 = require("../../Services/Logger");
class GetOrganizationLoginUrlQueryHandler {
    constructor(orgRepo) {
        this.orgRepo = orgRepo;
    }
    async execute(query) {
        const startTime = Date.now();
        try {
            (0, Logger_1.logDatabase)('Getting organization login URL', `organizationId: ${query.organizationId}`, 0, {
                organizationId: query.organizationId
            });
            const organization = await this.orgRepo.findById(query.organizationId);
            if (!organization) {
                (0, Logger_1.logWarning)('Organization not found for login URL request', {
                    organizationId: query.organizationId
                });
                return null;
            }
            if (!organization.url) {
                (0, Logger_1.logWarning)('Organization has no configured login URL', {
                    organizationId: query.organizationId,
                    organizationName: organization.name
                });
                return null;
            }
            const result = {
                organizationId: organization.id,
                organizationName: organization.name,
                loginUrl: organization.url
            };
            (0, Logger_1.logDatabase)('Organization login URL retrieved successfully', `organizationId: ${query.organizationId}`, Date.now() - startTime, {
                organizationId: organization.id,
                organizationName: organization.name,
                hasUrl: !!organization.url
            });
            return result;
        }
        catch (error) {
            (0, Logger_1.logError)('GetOrganizationLoginUrlQueryHandler error', error);
            throw new Error('Failed to retrieve organization login URL');
        }
    }
}
exports.GetOrganizationLoginUrlQueryHandler = GetOrganizationLoginUrlQueryHandler;
//# sourceMappingURL=GetOrganizationLoginUrlQueryHandler.js.map