package storage

import (
	"git.insit.tech/sas/rtsp_proxy/proto/common"
	"os"
	"strconv"
	"time"
)

// CreateFileName creates FileName structure.
func CreateFileName(dirData string, resolutions []string, cutURI string, period int, number int) *common.FileName {
	fn := common.FileName{
		Path:     dirData + "/" + cutURI + "/" + resolutions[0],
		TimeNow:  strconv.FormatInt(time.Now().Unix(), 10),
		Name:     "seg",
		Number:   number,
		Duration: float64(period),
	}

	return &fn
}

// ReadDir reads directory and returns the slice of files in th directory.
func ReadDir(dirData string) ([]os.DirEntry, error) {
	files, err := os.ReadDir(dirData)
	if err != nil {
		return nil, err
	}

	return files, nil
}

// Exists check if the file or directory exists.
func Exists(file string) bool {
	_, err := os.Stat(file)
	if err == nil {
		return true
	}

	return false
}
