package main

import (
	"log"

	"github.com/remogatto/cloud"
	"gogs.carduccidante.edu.it/karmen/core/generator"
	"gogs.carduccidante.edu.it/karmen/core/generator/generators/department"
)

func main() {
	conf := new(generator.Config)

	err := generator.ReadFile("config.yaml", conf)
	if err != nil {
		panic(err)
	}

	log.Printf("Connecting to the cloud...")
	client, err := cloud.Dial(
		conf.Cloud.Url,
		conf.Cloud.Username,
		conf.Cloud.Password,
	)
	if err != nil {
		log.Println(err)
	}

	err = client.Mkdir("Documents/Example 1")
	if err != nil {
		panic(err)

	}

	// Upload resources on the cloud

	if files, err := client.UploadDir("resources/*", "Documents/Example 1"); err != nil {
		panic(err)
	} else {
		for _, file := range files {
			log.Println(file, " was uploaded.")
		}
	}

	gen := department.NewDepartmentGenerator(conf)
	gen.Run()
}
