package transcoder

import (
	"log"
	"path/filepath"
	"os"
)

type Repository struct {
	basePath string
}

func NewRepository(path string) *Repository {
	// make sure repository base directory exists
	create_repo_dir(path)

	// make sure the ingest, archive, and output directories exist
	subDirs := []string{"ingest", "archive", "output"}
	for _, d := range subDirs {
		subPath := filepath.Join(path, d)
		create_repo_dir(subPath)
	}

	r := new(Repository)
	r.basePath = path
	return r
}

func create_repo_dir(path string) {
	_, err := os.Stat(path)
	if os.IsNotExist(err) {
		log.Printf("Creating directory %s.\n", path)
		os.Mkdir(path, os.ModeDir)
	} else {
		log.Printf("Directory %s already exists.\n", path)
	}
}
