import { BufferReader } from '@aztec/foundation/serialize';
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
import isEqual from 'lodash.isequal';
import { z } from 'zod';
import { LogId } from './log_id.js';
import { UnencryptedL2Log } from './unencrypted_l2_log.js';
/**
 * Represents an individual unencrypted log entry extended with info about the block and tx it was emitted in.
 */
export class ExtendedUnencryptedL2Log {
    constructor(
    /** Globally unique id of the log. */
    id, 
    /** The data contents of the log. */
    log) {
        this.id = id;
        this.log = log;
    }
    static random() {
        return new ExtendedUnencryptedL2Log(LogId.random(), UnencryptedL2Log.random());
    }
    static get schema() {
        return z
            .object({
            id: LogId.schema,
            log: UnencryptedL2Log.schema,
        })
            .transform(ExtendedUnencryptedL2Log.from);
    }
    static from(fields) {
        return new ExtendedUnencryptedL2Log(fields.id, fields.log);
    }
    /**
     * Serializes log to a buffer.
     * @returns A buffer containing the serialized log.
     */
    toBuffer() {
        return Buffer.concat([this.id.toBuffer(), this.log.toBuffer()]);
    }
    /**
     * Serializes log to a string.
     * @returns A string containing the serialized log.
     */
    toString() {
        return bufferToHex(this.toBuffer());
    }
    /**
     * Serializes log to a human readable string.
     * @returns A human readable representation of the log.
     */
    toHumanReadable() {
        return `${this.id.toHumanReadable()}, ${this.log.toHumanReadable()}`;
    }
    /**
     * Checks if two ExtendedUnencryptedL2Log objects are equal.
     * @param other - Another ExtendedUnencryptedL2Log object to compare with.
     * @returns True if the two objects are equal, false otherwise.
     */
    equals(other) {
        return isEqual(this, other);
    }
    /**
     * Deserializes log from a buffer.
     * @param buffer - The buffer or buffer reader containing the log.
     * @returns Deserialized instance of `Log`.
     */
    static fromBuffer(buffer) {
        const reader = BufferReader.asReader(buffer);
        const logId = LogId.fromBuffer(reader);
        const log = UnencryptedL2Log.fromBuffer(reader);
        return new ExtendedUnencryptedL2Log(logId, log);
    }
    /**
     * Deserializes `ExtendedUnencryptedL2Log` object from a hex string representation.
     * @param data - A hex string representation of the log.
     * @returns An `ExtendedUnencryptedL2Log` object.
     */
    static from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