<?php
$options = getopt('o:');

$operation = $options['o'] ?? null;

if (!$operation) {
    echo "\n Error: Missing operation type, use -o with param (copyCSS).\n\n";
    exit(1);
}

if ($operation === 'copyCSS') {
    Deploy::copyRessource('css');
}

class Deploy {

    private static $cssFile = [
        'kt-scheme.min.css' => 'vendor/knah-tsaeb/kt-color-scheme/public/assets/css/kt-scheme.min.css',
        'kt-rules.min.css' => 'vendor/knah-tsaeb/kt-color-scheme/public/assets/css/kt-rules.min.css'
    ];

    private static $baseDestPath = 'tpl/myShaarli/';

    static function copyRessource($type) {

        if (!is_dir(self::$baseDestPath . $type)) {
            echo "\n Error: destination dir ('".self::$baseDestPath.$type."/') does not exist, please create it before run composer update/install \n \n\n";
            exit(1);
        }

        foreach (self::${$type . 'File'} as $fileName => $file) {
            if (file_exists($file)) {
                copy($file, self::$baseDestPath . $type . '/' . $fileName);
            }
        }
        exit(0);
    }
}