<?php
namespace MatthiasWeb\RealMediaLibrary\lite\folder;

use MatthiasWeb\RealMediaLibrary\order\Sortable;
use Exception;

// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- This class throws internal exceptions only.

// @codeCoverageIgnoreStart
defined('ABSPATH') or die('No script kiddies please!'); // Avoid direct file request
// @codeCoverageIgnoreEnd

/**
 * This class creates a collection object. (Type 1)
 * See parent classes / interfaces for better documentation.
 */
class Collection extends Sortable {
    // Documented in Creatable
    public function insert($ids, $supress_validation = false, $isShortcut = false) {
        throw new Exception(__('A collection cannot contain files.', 'real-media-library-lite'));
    }

    // Documented in Creatable
    public static function create($rowData) {
        $result = new Collection($rowData->id);
        $result->setParent($rowData->parent);
        $result->setName($rowData->name, $rowData->supress_validation);
        $result->setRestrictions($rowData->restrictions);
        return $result;
    }

    // Documented in Creatable
    public static function instance($rowData) {
        return new Collection(
            $rowData->id,
            $rowData->parent,
            $rowData->name,
            $rowData->slug,
            $rowData->absolute,
            $rowData->ord,
            $rowData->cnt_result,
            $rowData
        );
    }

    // Documented in IFolder
    public function getAllowedChildrenTypes() {
        return [RML_TYPE_GALLERY, RML_TYPE_COLLECTION];
    }

    // Documented in IFolder
    public function getTypeName($default = null) {
        return parent::getTypeName($default === null ? __('Collection', 'real-media-library-lite') : $default);
    }

    // Documented in IFolder
    public function getTypeDescription($default = null) {
        return parent::getTypeDescription(
            $default === null
                ? __(
                    'A collection cannot contain files. But you can create other collections and <strong> galleries</strong> there.',
                    'real-media-library-lite'
                )
                : $default
        );
    }

    // Documented in IFolder
    public function getType() {
        return RML_TYPE_COLLECTION;
    }
}
