"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const EvmAddress_1 = __importDefault(require("../../../../../domain/context/contract/EvmAddress"));
require("reflect-metadata");
const GetImpactDataQueryError_1 = require("./error/GetImpactDataQueryError");
const GetImpactDataQuery_1 = require("./GetImpactDataQuery");
const GetImpactDataQueryHandler_1 = require("./GetImpactDataQueryHandler");
describe("GetImpactDataQueryHandler", () => {
    let handler;
    let mockQueryAdapter;
    let mockAccountService;
    beforeEach(() => {
        mockQueryAdapter = {
            getImpactData: jest.fn(),
        };
        mockAccountService = {
            getAccountEvmAddress: jest.fn(),
        };
        // Instantiate handler directly with mocks to avoid container issues
        handler = new GetImpactDataQueryHandler_1.GetImpactDataQueryHandler(mockQueryAdapter, mockAccountService);
    });
    it("should return impact data successfully", async () => {
        // Arrange
        const securityId = "0.0.123456";
        const evmAddress = new EvmAddress_1.default("0x1234567890123456789012345678901234567890");
        const mockResult = [2000n, 1000n, 500n, 2, 10000n];
        mockAccountService.getAccountEvmAddress.mockResolvedValue(evmAddress);
        mockQueryAdapter.getImpactData.mockResolvedValue(mockResult);
        const query = new GetImpactDataQuery_1.GetImpactDataQuery(securityId);
        // Act
        const result = await handler.execute(query);
        // Assert
        expect(result).toBeInstanceOf(GetImpactDataQuery_1.GetImpactDataQueryResponse);
        expect(result.maxDeviationCap).toBe("2000");
        expect(result.baseLine).toBe("1000");
        expect(result.maxDeviationFloor).toBe("500");
        expect(result.impactDataDecimals).toBe(2);
        expect(result.adjustmentPrecision).toBe("10000");
        expect(mockAccountService.getAccountEvmAddress).toHaveBeenCalledWith(securityId);
        expect(mockQueryAdapter.getImpactData).toHaveBeenCalledWith(evmAddress);
    });
    it("should throw GetImpactDataQueryError when service fails", async () => {
        // Arrange
        const securityId = "0.0.123456";
        const error = new Error("Service error");
        mockAccountService.getAccountEvmAddress.mockRejectedValue(error);
        const query = new GetImpactDataQuery_1.GetImpactDataQuery(securityId);
        // Act & Assert
        await expect(handler.execute(query)).rejects.toThrow(GetImpactDataQueryError_1.GetImpactDataQueryError);
    });
});
