#![allow(unused_doc_comments)]

// Copyright (c) 2025, Huawei Technologies Co., Ltd.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0  (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


pub mod model;

use anyhow::{anyhow, Result};
pub use model::*;

mod processors;
use processors::*;

mod pbtxt;
use pbtxt::*;

pub mod dot;
use dot::*;

mod dispatch;
pub use dispatch::{FileType, FileType::*};

pub mod str_ext;
pub use str_ext::StrExt;

pub mod string_ext;
pub mod om_json;
mod serde_helper;
pub use string_ext::SmartStringExt;
use crate::om_json::parse_om_json;

pub type StdString = String;

pub fn parse_bin(path: &str) -> Result<Model> {
    match FileType::from(path) {
        ONNX => parse_onnx(path),
        MindIR => parse_mindir(path),
        GeIR => parse_geir(path),
        PBTXT => {
            let mut model = parse_onnx_pbtxt(path)?;
            model.populate_node_connections();
            Ok(model)
        },
        DOT => {
            let content = read_dot(path)?;
            let model = parse_dot(&content)?;
            Ok(model)
        },
        OmJson => {
            let mut model = parse_om_json(path)?;
            model.populate_node_connections();
            Ok(model)
        }
        Unsupported => Err(anyhow!(format!("Unsupported FileType: {path:?}"))),
    }
}