/** @internal NOTE: Internal APIs. Subject to change. Use of these APIs in production applications is not supported. */ /** */
import { Discipline } from './discipline';
import { BimProduct } from './BimProduct';
import {
    BimRegion,
    BimTransform,
    BimProductMeshDescriptor,
    BimIfcStyleDTO,
    BimObjectAttributeDTO,
    BimTypeObjectDTO
} from './bim-format-types';

export interface BimIfcIndexDTO {
    // How one unit in the ifc worldspace is represented
    // in meters, mm etc. Can be used to create a scale transform
    // allowing us to show a model in Inches for example
    readonly modelFactors: {
        readonly oneFoot: number;
        readonly oneInch: number;
        readonly oneKilometer: number;
        readonly oneMeter: number;
        readonly oneMetre: number;
        readonly oneMile: number;
        readonly oneMilliMeter: number;
        readonly oneMilliMetre: number;
    };
    readonly regions: BimRegion[];
    readonly classes: string[]; // When received as json it actually is an array. We transform it into a lookup
    readonly typeClasses: string[];
    readonly texts: string[];
    readonly objectAttributes: BimObjectAttributeDTO[];
    readonly types: BimTypeObjectDTO[];
    readonly transforms: (BimTransform | undefined)[]; // List of all transforms
    readonly meshDescriptors: (BimProductMeshDescriptor | undefined)[];
    readonly styles: BimIfcStyleDTO[];
    readonly project: BimProduct;
}

export interface BimIfcIndex {
    // How one unit in the ifc worldspace is represented
    // in meters, mm etc. Can be used to create a scale transform
    // allowing us to show a model in Inches for example
    readonly modelFactors: {
        readonly oneFoot: number;
        readonly oneInch: number;
        readonly oneKilometer: number;
        readonly oneMeter: number;
        readonly oneMetre: number;
        readonly oneMile: number;
        readonly oneMilliMeter: number;
        readonly oneMilliMetre: number;
    };
    readonly discipline: Discipline;
    readonly regions: BimRegion[];
    readonly classes: string[]; // When received as json it actually is an array. We transform it into a lookup
    readonly typeClasses: string[];
    readonly texts: string[];
    readonly objectAttributes: BimObjectAttributeDTO[];
    readonly types: BimTypeObjectDTO[];
    readonly transforms: (BimTransform | undefined)[]; // List of all transforms
    readonly meshDescriptors: (BimProductMeshDescriptor | undefined)[];
    readonly styles: BimIfcStyleDTO[];
    readonly project: BimProduct;
}

export class IfcFileIndex implements BimIfcIndex {
    readonly modelFactors: {
        readonly oneFoot: number;
        readonly oneInch: number;
        readonly oneKilometer: number;
        readonly oneMeter: number;
        readonly oneMetre: number;
        readonly oneMile: number;
        readonly oneMilliMeter: number;
        readonly oneMilliMetre: number;
    };

    readonly discipline: Discipline;
    readonly regions: BimRegion[];
    readonly classes: string[];
    readonly typeClasses: string[];
    readonly texts: string[];
    readonly objectAttributes: BimObjectAttributeDTO[];
    readonly types: BimTypeObjectDTO[];
    readonly transforms: (BimTransform | undefined)[];
    readonly meshDescriptors: (BimProductMeshDescriptor | undefined)[];
    readonly styles: BimIfcStyleDTO[];
    readonly project: BimProduct;

    public constructor(dto: BimIfcIndexDTO, discipline: Discipline) {
        this.modelFactors = dto.modelFactors;
        this.regions = dto.regions;
        this.classes = dto.classes;
        this.typeClasses = dto.typeClasses;
        this.texts = dto.texts;
        this.objectAttributes = dto.objectAttributes;
        this.types = dto.types;
        this.transforms = dto.transforms;
        this.meshDescriptors = dto.meshDescriptors;
        this.styles = dto.styles;
        this.project = dto.project;
        this.discipline = discipline;

        this.styles.push({
            r: 50,
            g: 180,
            b: 50,
            a: 255, // ALPHA
            diffuseFactor: 0,
            diffuseTransmissionFactor: 0,
            hash: 'hash',
            name: 'ifcSpaceColor',
            reflectionFactor: 0,
            specularFactor: 0,
            transmissionFactor: 0
        });
        this.texts.push('undefined'); // Always add undefined for missing names, descriptions etc
        this.discipline = discipline;
    }
}
