import {ManipulatorInterfaceType} from '../types'
import fs from 'fs-extra'
import path from 'path'
import utils from '../utils'

type DeleterFileConfig = {
    name: string //name without ext
    ext?: string //name without ext
    path: string //path file locate file folder
}
type DeleterFolderOutConfig = {
    path: string //path file locate
    name: string //name folder
}

class Deleter implements ManipulatorInterfaceType {
    async file(config: DeleterFileConfig) {
        try {
            //file names
            const startFullName = utils.getNameByConfig(config)
            //file pathes
            const startFullPath = path.resolve(config.path, startFullName)
            //operations
            await fs.remove(startFullPath)
            return true
        } catch (e) {
            console.log(this.constructor.name, `[${this.file.name}]`, config.name, e)
            return false
        }
    }

    async folder(config: DeleterFolderOutConfig) {
        try {
            //file names
            const startFullName = `${config.name}`
            //file pathes
            const startFullPath = path.resolve(config.path, startFullName)
            //operations
            await fs.remove(startFullPath)
            return true
        } catch (e) {
            console.log(this.constructor.name, `[${this.folder.name}]`, config.name, e)
            return false
        }
    }
}

export default new Deleter()
