/*
==================================================================================
  Copyright (c) 2019 AT&T Intellectual Property.
  Copyright (c) 2019 Nokia

   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.
==================================================================================
*/

package xapp

import (
	"archive/zip"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
)

type Utils struct {
	baseDir string
	status  string
}

func NewUtils() *Utils {
	b := Config.GetString("controls.symptomdata.baseDir")
	if b == "" {
		b = "/tmp/symptomdata/"
	}

	return &Utils{
		baseDir: b,
	}
}

func (u *Utils) FileExists(f string) bool {
	_, err := os.Stat(f)
	return err == nil || os.IsExist(err)
}

func (u *Utils) CreateDir(path string) error {
	if u.FileExists(path) {
		os.RemoveAll(path)
	}
	err := os.MkdirAll(path, os.ModePerm)
	if err != nil {
		return err
	}
	os.Chmod(path, os.ModePerm)
	return nil
}

func (u *Utils) DeleteFile(fileName string) {
	os.Remove(fileName)
}

func (u *Utils) AddFileToZip(zipWriter *zip.Writer, filePath string, filename string) error {
	fileToZip, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer fileToZip.Close()

	info, err := fileToZip.Stat()
	if err != nil {
		return err
	}

	header, err := zip.FileInfoHeader(info)
	if err != nil {
		return err
	}

	if strings.HasPrefix(filename, filePath) {
		filename = strings.TrimPrefix(filename, filePath)
	}
	header.Name = filename
	header.Method = zip.Deflate

	writer, err := zipWriter.CreateHeader(header)
	if err != nil {
		return err
	}
	if info.Size() > 0 {
		_, err = io.Copy(writer, fileToZip)
	}
	return err
}

func (u *Utils) ZipFiles(newZipFile *os.File, filePath string, files []string) error {
	defer newZipFile.Close()
	zipWriter := zip.NewWriter(newZipFile)
	defer zipWriter.Close()
	for _, file := range files {
		if err := u.AddFileToZip(zipWriter, filePath, file); err != nil {
			Logger.Error("AddFileToZip() failed: %+v", err.Error())
			return err
		}
	}

	return nil
}

func (u *Utils) FetchFiles(filePath string, fileList []string) []string {
	files, err := ioutil.ReadDir(filePath)
	if err != nil {
		Logger.Error("ioutil.ReadDir failed: %+v", err)
		return nil
	}
	for _, file := range files {
		if !file.IsDir() {
			fileList = append(fileList, filepath.Join(filePath, file.Name()))
		} else {
			subPath := filepath.Join(filePath, file.Name())
			subFiles, _ := ioutil.ReadDir(subPath)
			for _, subFile := range subFiles {
				if !subFile.IsDir() {
					fileList = append(fileList, filepath.Join(subPath, subFile.Name()))
				} else {
					fileList = u.FetchFiles(filepath.Join(subPath, subFile.Name()), fileList)
				}
			}
		}
	}
	return fileList
}

func (u *Utils) WriteToFile(fileName string, data string) error {
	f, err := os.Create(fileName)
	defer f.Close()

	if err != nil {
		Logger.Error("Unable to create file %s': %+v", fileName, err)
	} else {
		_, err := io.WriteString(f, data)
		if err != nil {
			Logger.Error("Unable to write to file '%s': %+v", fileName, err)
			u.DeleteFile(fileName)
		}
	}
	return err
}
