import type Point from "@arcgis/core/geometry/Point";
import type SpatialReference from "@arcgis/core/geometry/SpatialReference";
import type FeatureLayer from "@arcgis/core/layers/FeatureLayer";
import type GeoJSONLayer from "@arcgis/core/layers/GeoJSONLayer";
import type GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
import type { IEntity, IPolylineEntity, ILwpolylineEntity, ILineEntity } from "dxf-parser";
import type { DxfToGeoJsonLineMapper, DxfToGeoJsonPolygonMapper, DxfToGeoJsonTextMapper, DxfToGeoJsonInsertBlockMapper } from "./_dxfConverters";
/**
 * A single coordinate point in 2D or 3D space.
 */
export interface DxfPoint {
    /**
     * The x-coordinate.
     */
    x: number;
    /**
     * The y-coordinate.
     */
    y: number;
    /**
     * The z-coordinate.
     */
    z?: number;
}
/**
 * Represents scale factors for the X, Y, and Z axes in a DXF file. Typically
 * used to define scaling transformations applied to block inserts or entities.
 */
export interface DxfScale {
    /**
     * Scale factor along the X-axis.
     */
    x: number;
    /**
     * Scale factor along the Y-axis.
     */
    y: number;
    /**
     * Scale factor along the Z-axis.
     */
    z: number;
}
/**
 * Represents a DXF block that groups multiple DXF entities together. A block
 * can be inserted, transformed, or reused within the DXF drawing.
 */
export interface DxfBlock {
    /**
     * The type of block (numeric or string identifier).
     */
    type: string | number;
    /**
     * List of DXF entities that make up the block.
     */
    entities: DxfEntity[];
    /**
     * The name of the block.
     */
    name: string;
    /**
     * Optional insertion point or reference position for the block.
     */
    position?: DxfPoint;
    /**
     * Optional layer name associated with the block.
     */
    layer?: string;
    /**
     * Optional color index or code for the block.
     */
    color?: number;
}
/**
 * Represents a single DXF entity. Entities can include points, lines, circles,
 * arcs, text, or polylines.
 */
export interface DxfEntity {
    /**
     * Type of the DXF entity (e.g., LINE, CIRCLE, TEXT).
     */
    type: string;
    /**
     * List of vertex coordinates defining geometry for polylines or shapes.
     */
    vertices?: DxfPoint[];
    /**
     * The layer on which this entity resides.
     */
    layer?: string;
    /**
     * Whether the shape entity represents a closed loop (for polylines).
     */
    shape?: boolean;
    /**
     * Whether the polyline is closed (end connects to start).
     */
    closed?: boolean;
    /**
     * The geometric center point (for circles or arcs).
     */
    center?: DxfPoint;
    /**
     * The radius (for circles and arcs).
     */
    radius?: number;
    /**
     * The start angle of an arc (in degrees).
     */
    startAngle?: number;
    /**
     * The end angle of an arc (in degrees).
     */
    endAngle?: number;
    /**
     * The text string value (for TEXT or MTEXT entities).
     */
    text?: string;
    /**
     * Position of the entity (for TEXT, INSERT, etc.).
     */
    position?: DxfPoint;
    /**
     * Height of text (for TEXT or MTEXT entities).
     */
    height?: number;
    /**
     * Rotation angle of the entity (in degrees).
     */
    rotation?: number;
    /**
     * Optional name (for block references or named entities).
     */
    name?: string;
    /**
     * Optional scale factors applied to the entity or block reference.
     */
    scale?: DxfScale;
    /**
     * Optional dictionary of nested blocks referenced by this entity.
     */
    blocks?: Record<string, DxfBlock>;
    /**
     * Name of the block this entity references (if any).
     */
    blockName?: string;
    /**
     * Flag indicating whether this entity originated from a special block
     * reference.
     */
    isFromSpecialBlock?: boolean;
    /**
     * Color index or code for the entity.
     */
    color?: number;
}
/**
 * Defines properties shared by all DXF component dxfContext. Used to configure
 * renderers, color mappings, and spatial references for visualizing DXF data
 * within a mapping or rendering system.
 */
export interface DxfJsonComponentProperties {
    /**
     * Default color applied to DXF layers.
     */
    layerColor?: string;
    /**
     * Renderer configuration for point entities.
     */
    renderer_Object_Point?: Record<string, unknown>;
    /**
     * Renderer configuration for line entities.
     */
    renderer_Object_Line?: Record<string, unknown>;
    /**
     * Renderer configuration for polygon entities.
     */
    renderer_Object_Polygon?: Record<string, unknown>;
    /**
     * Raw parsed DXF data structure.
     */
    dxf?: Record<string, unknown>;
    /**
     * The source spatial reference of the DXF data.
     */
    sourceSR?: SpatialReference;
    /**
     * The target spatial reference used for projection or rendering.
     */
    targetSR?: SpatialReference;
}
/**
 * Simple line style definition (may include dash patterns).
 */
export interface LineStyle {
    /**
     * Numeric pattern describing dash and gap sequence.
     */
    pattern?: number[];
}
/**
 * Represents the JSON structure for a simple fill symbol, used for serializing
 * symbol properties.
 */
export interface SimpleFillSymbolJSON {
    /**
     * The fill style of the symbol.
     */
    style?: "solid" | "none";
    /**
     * The color of the fill, represented as an RGBA array.
     */
    color?: number[];
    /**
     * The outline of the symbol.
     */
    outline?: {
        /**
         * The color of the outline, represented as an RGBA array.
         */
        color?: number[];
        /**
         * The width of the outline.
         */
        width?: number;
        /**
         * Optional type discriminator for autocasting.
         */
        type?: "simple-line";
    };
}
/**
 * Renderer definition for line entities. Each record key corresponds to a DXF
 * layer or classification.
 */
export type RendererObjectLine = Record<string, {
    /**
     * The renderer value (typically layer name or identifier).
     */
    value: string;
    /**
     * Symbol definition for rendering the line.
     */
    symbol: {
        /**
         * Symbol type, always "simple-line" for line rendering.
         */
        type: "simple-line";
        /**
         * Line style pattern or keyword (e.g., solid, dash, dot).
         */
        style: "solid" | "dash" | "dot" | "dash-dot" | "long-dash" | "long-dash-dot" | "short-dash" | "dash-dot" | "short-dash-dot" | LineStyle;
        /**
         * Width of the rendered line in pixels or map units.
         */
        width: number;
        /**
         * Optional RGBA color definition.
         */
        color?: number[];
    };
}>;
/**
 * Renderer definition for polygon entities. Used to visualize DXF closed shapes
 * and filled areas.
 */
export type RendererObjectPolygon = Record<string, {
    /**
     * The renderer value (usually layer name).
     */
    value: string;
    /**
     * Symbol definition for rendering polygons.
     */
    symbol: {
        /**
         * Symbol type, always "simple-fill" for polygons.
         */
        type: "simple-fill";
        /**
         * Fill style, can be solid or none.
         */
        style: "none" | "solid" | "dash" | "dot" | "dash-dot" | "long-dash" | "long-dash-dot" | "short-dash" | "dash-dot" | "short-dash-dot";
        /**
         * Optional RGBA fill color.
         */
        color?: number[];
        /**
         * Optional outline definition for polygon borders.
         */
        outline?: {
            /**
             * Outline color as RGBA.
             */
            color: number[];
            /**
             * Outline width in pixels or map units.
             */
            width?: number;
        };
    };
}>;
/**
 * Entry definition for polygon renderer arrays.
 */
export interface RendererPolygonEntry {
    /**
     * Renderer classification value (e.g., layer name).
     */
    value: string;
    /**
     * Symbol definition for the polygon.
     */
    symbol: {
        /**
         * Symbol type (always "simple-fill").
         */
        type: "simple-fill";
        /**
         * Fill style (always "solid" here).
         */
        style: "solid";
        /**
         * Fill color as RGBA array.
         */
        color: number[];
        /**
         * Outline properties for the polygon.
         */
        outline: {
            /**
             * Outline color as RGBA array.
             */
            color: number[];
            /**
             * Outline width in pixels or map units.
             */
            width: number;
        };
    };
}
/**
 * Simple marker symbol used for rendering point entities.
 */
export interface SimpleMarkerSymbolDXF {
    /**
     * Marker symbol type (always "simple-marker").
     */
    type: "simple-marker";
    /**
     * Marker shape style.
     */
    style: "none" | "circle" | "cross" | "square" | "x" | "diamond" | "triangle" | "path";
    /**
     * Marker size in pixels or map units.
     */
    size: number;
    /**
     * Optional fill color as RGBA array.
     */
    color?: number[];
}
/**
 * Renderer definition for point entities. Each record key represents a DXF
 * layer or symbol classification.
 */
export type RendererObjectPoint = Record<string, {
    /**
     * Renderer value (e.g., layer or category name).
     */
    value: string;
    /**
     * Symbol definition for point rendering.
     */
    symbol: SimpleMarkerSymbolDXF;
}>;
/**
 * Represents a DXF TEXT entity with text positioning and formatting attributes.
 */
export interface ITextEntityExtended extends IEntity {
    /**
     * Start point of the text entity.
     */
    startPoint: {
        x: number;
        y: number;
    };
    /**
     * Text string value.
     */
    text?: string;
    /**
     * Alternative text content field.
     */
    string?: string;
    /**
     * Tag or label identifier for the text.
     */
    tag?: string;
    /**
     * Text rotation angle in degrees.
     */
    rotation?: number;
    /**
     * Text height.
     */
    textHeight?: number;
    /**
     * The block this text entity belongs to.
     */
    block?: boolean;
    /**
     * The horizontal alignment of the text.
     */
    halign?: number;
}
/**
 * Represents a DXF MTEXT (multiline text) entity.
 */
export interface IMTextEntity extends IEntity {
    /**
     * Position of the text insertion point.
     */
    position: DxfPoint;
    /**
     * Text content.
     */
    text?: string;
    /**
     * Optional string content (alternative key).
     */
    string?: string;
    /**
     * Attribute tag associated with the text.
     */
    tag?: string;
    /**
     * Rotation angle of the text in degrees.
     */
    rotation?: number;
    /**
     * Text height.
     */
    height?: number;
    /**
     * Width of the multiline text block.
     */
    width?: number | undefined;
    /**
     * Attachment point for text alignment.
     */
    attachmentPoint?: number | undefined;
}
/**
 * Represents a DXF ATTDEF (attribute definition) entity.
 */
export interface IAttDefEntity extends IEntity {
    /**
     * Start point of the attribute definition.
     */
    startPoint: DxfPoint;
    /**
     * Optional end point for the attribute definition.
     */
    endPoint?: DxfPoint;
    /**
     * Text content associated with the attribute.
     */
    text?: string;
    /**
     * Attribute tag identifier.
     */
    tag?: string;
    /**
     * Prompt message displayed in block insertion.
     */
    prompt?: string;
    /**
     * Name of the block this attribute belongs to.
     */
    blockName?: string;
    /**
     * Text Height of the attribute text.
     */
    textHeight?: number;
    /**
     * Height of the attribute text.
     */
    height?: number;
    /**
     * Rotation angle of the text.
     */
    rotation?: number;
    /**
     * Optional horizontal justification.
     */
    horizontalJustification?: number | undefined;
}
/**
 * Extended interface for POLYLINE entities.
 */
export interface IPolylineEntityExtended extends IPolylineEntity {
    /**
     * Whether the polyline is closed.
     */
    closed?: boolean;
    /**
     * The width of the polyline.
     */
    width?: number;
}
/**
 * Extended interface for LWPOLYLINE entities.
 */
export interface ILwpolylineEntityExtended extends ILwpolylineEntity {
    /**
     * Whether this lightweight polyline is closed (DXF flag 1).
     */
    closed?: boolean;
}
/**
 * Extended interface for LINE entities, including optional block reference.
 */
export interface ILineEntityExtended extends ILineEntity {
    /**
     * The optional block name this line belongs to.
     */
    blockName?: string;
}
/**
 * Base table definition used in DXF file tables section.
 */
export interface IBaseTable {
    /**
     * Unique handle identifier for this table.
     */
    handle: string;
    /**
     * Handle of the owner object.
     */
    ownerHandle: string;
}
/**
 * Represents a DXF viewport table entry.
 */
export interface IViewPort {
    /**
     * Name of the viewport.
     */
    name: string;
    /**
     * Lower-left corner of the viewport.
     */
    lowerLeftCorner: DxfPoint;
    /**
     * Upper-right corner of the viewport.
     */
    upperRightCorner: DxfPoint;
    /**
     * Center point of the viewport.
     */
    center: DxfPoint;
    /**
     * Snap base point for the viewport.
     */
    snapBasePoint: DxfPoint;
    /**
     * Snap spacing setting.
     */
    snapSpacing: DxfPoint;
    /**
     * Grid spacing setting.
     */
    gridSpacing: DxfPoint;
    /**
     * Viewing direction vector from the target.
     */
    viewDirectionFromTarget: DxfPoint;
    /**
     * Viewing target coordinates.
     */
    viewTarget: DxfPoint;
    /**
     * Lens length for the viewport camera.
     */
    lensLength: number;
    /**
     * Front clipping plane setting.
     */
    frontClippingPlane: string | number | boolean;
    /**
     * Back clipping plane setting.
     */
    backClippingPlane: string | number | boolean;
    /**
     * View height of the viewport.
     */
    viewHeight: number;
    /**
     * Snap rotation angle in radians.
     */
    snapRotationAngle: number;
    /**
     * View twist angle in radians.
     */
    viewTwistAngle: number;
    /**
     * Orthographic projection type.
     */
    orthographicType: string;
    /**
     * UCS origin point.
     */
    ucsOrigin: DxfPoint;
    /**
     * UCS X-axis vector.
     */
    ucsXAxis: DxfPoint;
    /**
     * UCS Y-axis vector.
     */
    ucsYAxis: DxfPoint;
    /**
     * Render mode for the viewport.
     */
    renderMode: string;
    /**
     * Default lighting type.
     */
    defaultLightingType: string;
    /**
     * Indicates if default lighting is enabled.
     */
    defaultLightingOn: string;
    /**
     * Owner handle reference.
     */
    ownerHandle: string;
    /**
     * Ambient light color index.
     */
    ambientColor: number;
}
/**
 * Represents a DXF line type definition.
 */
export interface ILineType {
    /**
     * Name of the line type.
     */
    name: string;
    /**
     * Description of the line type.
     */
    description: string;
    /**
     * Dash pattern definition.
     */
    pattern: string[];
    /**
     * Total pattern length.
     */
    patternLength: number;
}
/**
 * Represents the attributes for a text graphic.
 *
 * @interface TextGraphicAttr
 */
export interface TextGraphicAttr {
    /**
     * The horizontal alignment of the text.
     *
     * @type {"left" | "right" | "center"}
     */
    horizontal: "left" | "right" | "center";
    /**
     * The vertical alignment of the text.
     *
     * @type {"baseline" | "bottom" | "middle" | "top"}
     */
    vertical: "baseline" | "bottom" | "middle" | "top";
    /**
     * The text content of the graphic.
     *
     * @type {string}
     */
    textContent: string;
    /**
     * The base font size for the text.
     *
     * @type {number}
     */
    baseFontSize: number;
    /**
     * The rotation angle of the text in degrees.
     *
     * @type {number}
     */
    rotation: number;
    /**
     * The color of the text in a string format (e.g., "#FFFFFF" for white).
     *
     * @type {string}
     */
    color: string;
}
/**
 * Represents a DXF layer definition.
 */
export interface ILayer {
    /**
     * Layer name.
     */
    name: string;
    /**
     * Whether the layer is visible.
     */
    visible: boolean;
    /**
     * Color index associated with the layer.
     */
    colorIndex: number;
    /**
     * Color value (RGB integer).
     */
    color: number;
    /**
     * Whether the layer is frozen (not displayed).
     */
    frozen: boolean;
}
/**
 * Represents the DXF viewport table section.
 */
export interface IViewPortTable extends IBaseTable {
    /**
     * Collection of viewports defined in the table.
     */
    viewPorts: IViewPort[];
}
/**
 * Represents the DXF line type table section.
 */
export interface ILayerTypesTable extends IBaseTable {
    /**
     * Collection of line type definitions.
     */
    lineTypes: Record<string, ILineType>;
}
/**
 * Represents the DXF layer table section.
 */
export interface ILayersTable extends IBaseTable {
    /**
     * Collection of layer definitions.
     */
    layers: Record<string, ILayer>;
}
/**
 * Represents the full set of tables defined in a DXF file.
 */
export interface ITables {
    /**
     * Viewport table.
     */
    viewPort: IViewPortTable;
    /**
     * Line type table.
     */
    lineType: ILayerTypesTable;
    /**
     * Layer table.
     */
    layer: ILayersTable;
}
/**
 * Represents the core parsed DXF data dxfContext.
 */
export interface IDxfData {
    /**
     * The header section of the DXF file.
     */
    header: Record<string, unknown>;
    /**
     * DXF tables (viewports, layers, line types).
     */
    tables: ITables;
    /**
     * Collection of all entities parsed from the DXF.
     */
    entities: IEntity[];
    /**
     * Optional map of block definitions.
     */
    blocks?: Record<string, DxfBlock>;
}
/**
 * Context object for DXF-to-GeoJSON or map layer conversion.
 */
export interface IDxfJsonComponentContext {
    /**
     * Parsed DXF data structure.
     */
    dxf: IDxfData;
    /**
     * Renderer for point features.
     */
    renderer_Object_Point: RendererObjectPoint;
    /**
     * Renderer for line features.
     */
    renderer_Object_Line: RendererObjectLine;
    /**
     * Renderer for polygon features.
     */
    renderer_Object_Polygon: RendererObjectPolygon;
    /**
     * Source spatial reference.
     */
    sourceSR: SpatialReference;
    /**
     * Target spatial reference for transformation.
     */
    targetSR: SpatialReference;
    /**
     * Generated sublayers (GeoJSON or graphics layers).
     */
    subLayers: (GeoJSONLayer | GraphicsLayer | FeatureLayer)[];
    /**
     * DxfContext responsible for line entity processing.
     */
    dxfToGeoJsonLineMapper: DxfToGeoJsonLineMapper;
    /**
     * DxfContext responsible for polygon entity processing.
     */
    dxfToGeoJsonPolygonMapper: DxfToGeoJsonPolygonMapper;
    /**
     * DxfContext responsible for text entity processing.
     */
    dxfToGeoJsonTextMapper: DxfToGeoJsonTextMapper;
    /**
     * DxfContext responsible for insert block handling.
     */
    dxfToGeoJsonInsertBlockMapper: DxfToGeoJsonInsertBlockMapper;
    /**
     * Generated GeoJSON point features.
     */
    pointFeatures: GeoJSON.Feature[];
    /**
     * Generated GeoJSON line features.
     */
    lineFeatures: GeoJSON.Feature[];
    /**
     * Generated GeoJSON polygon features.
     */
    polygonFeatures: GeoJSON.Feature[];
    /**
     * Generated GeoJSON text features.
     */
    textFeatures: GeoJSON.Feature[];
    /**
     * Process DXF entities and convert them to GIS features.
     *
     * @param entity The entity or list of entities to process.
     */
    dxfEntities(entity: IEntity | IEntity[]): Promise<void>;
    /**
     * Convert raw XY coordinates into the target spatial reference.
     *
     * @param x X coordinate value.
     * @param y Y coordinate value.
     * @returns Converted coordinate pair.
     */
    convertToSpatialReference(x: number, y: number): Promise<[number, number]>;
    /**
     * Project an array of points into the target spatial reference.
     *
     * @param points Array of points to project.
     * @returns Array of converted coordinate pairs.
     */
    projectMany(points: Point[]): Promise<[number, number][]>;
    /**
     * Convert a DXF integer color value to an RGB array.
     *
     * @param colorInt Integer color value.
     * @returns RGB array.
     */
    intToRGB(colorInt: number): number[];
    /**
     * The original file name of the DXF file.
     */
    fileName?: string;
    /**
     * A sanitized version of the file name suitable for use in an ID.
     */
    sanitizedFileName?: string;
    /**
     * The end coordinate of the last processed line or arc segment, used for
     * determining continuity. It is `undefined` if there is no previous segment
     * or if continuity is broken.
     */
    lastLineEnd?: [number, number] | undefined;
    /**
     * A running index to provide unique colors for entities.
     */
    colorIndex: number;
    /**
     * The layer of the last processed line or arc segment. This is used in
     * conjunction with `lastLineEnd` to ensure that line segments are only
     * merged if they belong to the same layer.
     */
    lastLineLayer?: string | undefined;
}
