import { Epsg } from '../epsg.js';
import { Citm2000Tms } from './citm2000.js';
import { GoogleTms } from './google.js';
import { Nztm2000QuadTms, Nztm2000Tms } from './nztm2000.js';
export const TileMatrixSets = {
    /** All TileMatrixSets that are currently supported */
    All: [GoogleTms, Nztm2000Tms, Nztm2000QuadTms, Citm2000Tms],
    /** Default mapping of EPSG code to Tile matrix set */
    Defaults: new Map([
        [Epsg.Google.code, GoogleTms],
        [Epsg.Nztm2000.code, Nztm2000Tms],
        [Epsg.Citm2000.code, Citm2000Tms],
    ]),
    /**
     * Get a tile matrix set by EPSG Code
     * @throws if no default mapping is made
     */
    get(epsg) {
        const tms = this.tryGet(epsg);
        if (tms == null)
            throw new Error('Failed to lookup TileMatrixSet: ' + String(epsg));
        return tms;
    },
    /** Attempt to find a mapping from a EPSG code to a default tile matrix set  */
    tryGet(epsg) {
        if (epsg == null)
            return null;
        if (typeof epsg === 'number')
            return this.Defaults.get(epsg) ?? null;
        return this.Defaults.get(epsg.code) ?? null;
    },
    /**
     * Find a tile matrix set given a identifier or epsg string
     * @param identifier Tile matrix set identifier
     * @param caseSensitive Should this compare case sensitively
     */
    find(identifier, caseSensitive = true) {
        if (identifier == null)
            return null;
        const epsg = Epsg.parse(identifier);
        if (epsg != null)
            return TileMatrixSets.tryGet(epsg);
        if (caseSensitive) {
            for (const tileMatrix of TileMatrixSets.All) {
                if (tileMatrix.identifier === identifier)
                    return tileMatrix;
            }
            return null;
        }
        for (const tileMatrix of TileMatrixSets.All) {
            if (tileMatrix.identifier.toLowerCase() === identifier.toLowerCase())
                return tileMatrix;
        }
        return null;
    },
};
//# sourceMappingURL=index.js.map