func DeserializeModel(m string) (Model, error) {
	var model Model
	err := json.Unmarshal([]byte(m), &model)
	if err != nil {
		return Model{}, err
	}
	return model, nil
}
DeserializeModel takes a JSON string in input and try to convert it to a Model object
package models
import (
	"errors"
	"fmt"
	"strings"
	"github.com/rtlnl/phoenix/pkg/db"
	"github.com/rtlnl/phoenix/utils"
)
const (
	tableModels = "models"
)
type Model struct {
	Name         string   `json:"name" description:"name of the model that will be used"`
	SignalOrder  []string `json:"signalOrder" description:"list of ordered signals"`
	Concatenator string   `json:"concatenator" description:"character used as concatenator for SignalOrder {'|','#','_','-'}"`
}
func NewModel(name, concatenator string, signalOrder []string, dbc db.DB) (Model, error) {
	if ModelExists(name, dbc) {
		return Model{}, fmt.Errorf("model with name %s already exists", name)
	}
	if len(signalOrder) > 1 && concatenator == "" {
		return Model{}, errors.New("multiple signals are being specified but no concatenator. concatenator is missing")
	}
	if utils.StringInSlice(name, reservedNames) {
		return Model{}, fmt.Errorf("cannot use %s as name. this name is reserved", name)
	}
	model := Model{
		Name:         name,
		SignalOrder:  signalOrder,
		Concatenator: concatenator,
	}
	serialized, err := utils.SerializeObject(model)
	if err != nil {
		return Model{}, fmt.Errorf("could not serialize model. error: %s", err.Error())
	}
	if err := dbc.AddOne(tableModels, name, serialized); err != nil {
		return Model{}, err
	}
	return model, nil
}
func ModelExists(name string, dbc db.DB) bool {
	if _, err := dbc.GetOne(tableModels, name); err != nil {
		return false
	}
	return true
}
func GetModel(name string, dbc db.DB) (Model, error) {
	if !ModelExists(name, dbc) {
		return Model{}, fmt.Errorf("model with name %s not found", name)
	}
	m, err := dbc.GetOne(tableModels, name)
	if err != nil {
		return Model{}, err
	}
	return DeserializeModel(m)
}
func (m *Model) DeleteModel(dbc db.DB) error {
	if err := dbc.DeleteOne(tableModels, m.Name); err != nil {
		return fmt.Errorf("error in removing the model. error: %s", err.Error())
	}
	if err := dbc.DropTable(m.Name); err != nil {
		return fmt.Errorf("error in deleting the data of the model. error: %s", err.Error())
	}
	containers, _, err := GetAllContainers(dbc)
	if err != nil {
		return fmt.Errorf("error in retrieving the containers. error: %s", err.Error())
	}
	for _, container := range containers {
		tmp := container.Models
		container.Models = utils.RemoveElemFromSlice(m.Name, tmp)
		ser, err := utils.SerializeObject(container)
		if err != nil {
			return fmt.Errorf("failed to serialize container. error: %s", err.Error())
		}
		if err := dbc.AddOne(tableContainers, ContainerUniqueName(container.PublicationPoint, container.Campaign), ser); err != nil {
			return fmt.Errorf("failed to insert container in database. error: %s", err.Error())
		}
	}
	return nil
}
func (m *Model) UpdateSignalOrder(signalOrder []string, dbc db.DB) error {
	if err := dbc.DropTable(m.Name); err != nil {
		return fmt.Errorf("error in deleting the data of the model. error: %s", err.Error())
	}
	m.SignalOrder = signalOrder
	model, err := utils.SerializeObject(m)
	if err != nil {
		return fmt.Errorf("failed serialization of the model. error: %s", err.Error())
	}
	if err := dbc.AddOne(tableModels, m.Name, model); err != nil {
		return fmt.Errorf("error in storing the signalOrder in database. error: %s", err.Error())
	}
	return nil
}
func (m *Model) RequireSignalFormat() bool {
	if len(m.SignalOrder) > 1 && m.Concatenator != "" {
		return true
	}
	return false
}
func (m *Model) CorrectSignalFormat(s string) bool {
	res := strings.FieldsFunc(s, func(c rune) bool {
		r := []rune(m.Concatenator)
		if len(r) == 0 {
			return false
		}
		return c == r[0]
	})
	return len(m.SignalOrder) == len(res)
}
func GetAllModels(dbc db.DB) ([]Model, int, error) {
	var models []Model
	records, count, err := dbc.GetAllRecords(tableModels)
	if err != nil {
		return nil, -1, fmt.Errorf("error in returning all the models from the database. error: %s", err.Error())
	}
	for modelName := range records {
		m, err := GetModel(modelName, dbc)
		if err != nil {
			return nil, -1, err
		}
		models = append(models, m)
	}
	return models, count, nil
}
func (m *Model) GetDataPreview(dbc db.DB) (map[string]string, int, error) {
	records, count, err := dbc.GetAllRecords(m.Name)
	if err != nil {
		return nil, -1, fmt.Errorf("error in returning the data preview from the database. error: %s", err.Error())
	}
	return records, count, nil
}