package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"strconv"
	"time"
)

const (
	// Header is a generic XML header suitable for use with the output of Marshal.
	// This is not automatically added to any output of this package,
	// it is provided as a convenience.
	Header = `<?xml version="1.0" encoding="UTF-8"?>` + "\n"
)

func main() {

	t := time.Now()
	timestamp := t.Format("2006-01-02 15:04:05")
	timefile := t.Format("20060102150405")
	_, offset := t.Zone()
	var tzOffset string
	if offset >= 0 {
		tzOffset = "UTC+" + strconv.Itoa(offset/3600)
	} else {
		tzOffset = "UTC" + strconv.Itoa(offset/3600)
	}

	nrmFile := new(DataFile)

	nrmFile.FileHeader = FileHeader{
		TimeStamp:   timestamp,
		TimeZone:    tzOffset,
		VendorName:  "Ruijie Network",
		ElementType: "SMF",
		CmVersion:   "16.1.1",
	}

	nrmFile.XsiAttr = "http://www.w3.org/2001/XMLSchema-instance"
	nrmFile.XsiLoc = "file:///usr/loal/omc/etc/schema/cm-schema.xsd"
	nrmFile.Objects.ObjectType = "ManagedElement"
	for i := 1; i < 10; i++ {
		nrmFile.Objects.FieldName.N = append(nrmFile.Objects.FieldName.N, N{IAttr: i, Value: "Id"})
	}
	object := Object{RmUIDAttr: "1000HXSMF001",
		DnAttr:        "DC=www.ruijie.com.cn,SubNetwork=10001,SubNetwork=114214,ManagedElement=325",
		UserLabelAttr: "SMF_BJ_JC001", PVFlagAttr: "VNF", VMIDAttr: "kylin10.0-001-SMF", VNFInstanceIDAttr: "2bdd55b4-9018-41f4-af35-28b6828788"}
	for i := 1; i < 10; i++ {
		object.V = append(object.V, V{IAttr: i, Value: "SMF"})
	}
	nrmFile.Objects.FieldValue.Object = append(nrmFile.Objects.FieldValue.Object, object)
	object = Object{RmUIDAttr: "1000HXSMF002",
		DnAttr:        "DC=www.ruijie.com.cn,SubNetwork=10001,SubNetwork=114214,ManagedElement=325",
		UserLabelAttr: "SMF_BJ_JC001", PVFlagAttr: "VNF", VMIDAttr: "kylin10.0-002-SMF", VNFInstanceIDAttr: "2bdd55b4-9018-41f4-af35-28b6828788"}
	for i := 1; i < 10; i++ {
		object.V = append(object.V, V{IAttr: i, Value: "SMF"})
	}
	nrmFile.Objects.FieldValue.Object = append(nrmFile.Objects.FieldValue.Object, object)

	x, _ := xml.MarshalIndent(nrmFile, "", "	")
	x = append([]byte(xml.Header), x...)
	cmfile := fmt.Sprintf("./CM-HX-V%s-%s.xml", "16.1.1", timefile)
	ioutil.WriteFile(cmfile, x, 0664)
}
