<?php

namespace Hura8\Interfaces;

/**
 * Contain all entity types of this apps
 *
 * Dynamic Resolution Rules:
 * - Format: entity_type = [parent_type]-[sub_type]
 * Examples:
 *  + product: Product Entity
 *  + product-category: [Product parent-Entity]-[Product Category sub-Entity]
 *  + user-comment-reply: [user parent-Entity]-[user comment sub-Entity]-[user comment reply sub-Entity]
 *
 * - Model Resolution: EntityModel is auto inferred from entity name: EntityModel = Hura8\Components\[parent_type]\Model\[entity-name-upper first char]Model
 * Examples:
 *  + product: Hura8\Components\Product\Model\ProductModel
 *  + product-category: Hura8\Components\Product\Model\ProductCategoryModel
 *  + user-comment: Hura8\Components\User\Model\UserCommentModel
 *  + user-comment-reply: Hura8\Components\User\Model\UserCommentReplyModel
 *
 * - Controller Resolution: similar to the Model
 * Examples: public controllers
 *  + product: Hura8\Components\Product\PublicController\UProductController
 *  + product-category: Hura8\Components\Product\PublicController\UProductCategoryController
 *  + user-comment: Hura8\Components\User\PublicController\UUserCommentController
 *  + user-comment-reply: Hura8\Components\User\PublicController\UUserCommentReplyController
 *
 * Examples: admin controllers
 *  + product: Hura8\Components\Product\AdminController\AProductController
 *  + product-category: Hura8\Components\Product\AdminController\AProductCategoryController
 *  + user-comment: Hura8\Components\User\AdminController\AUserCommentController
 *  + user-comment-reply: Hura8\Components\User\AdminController\AUserCommentReplyController
 *
 */

final class EntityType
{
    /**
     * - Model Resolution: EntityModel is auto inferred from entity name: EntityModel = Hura8\Components\[parent_type]\Model\[entity-name-upper first char]Model
     * Examples:
     *  + product: Hura8\Components\Product\Model\ProductModel
     *  + product-category: Hura8\Components\Product\Model\ProductCategoryModel
     *  + user-comment: Hura8\Components\User\Model\UserCommentModel
     *  + user-comment-reply: Hura8\Components\User\Model\UserCommentReplyModel
     */
    public static function getModelClass(string $entity_type): string {
        $parts = array_map(function ($word){
            return ucfirst($word);
        }, explode("-", $entity_type));

        $parent = $parts[0];

        return "\\Hura8\\Components\\".$parent."\\Model\\".join("", $parts)."Model";
    }


    public static function getStatisticModelClass(string $entity_type): string {
        $parts = array_map(function ($word){
            return ucfirst($word);
        }, explode("-", $entity_type));

        $parent = $parts[0];

        return "\\Hura8\\Components\\".$parent."\\Model\\".join("", $parts)."StatisticModel";
    }


    /*
     * - Controller Resolution: similar to the Model
     * Examples: public controllers
     *  + product: Hura8\Components\Product\PublicController\UProductController
     *  + product-category: Hura8\Components\Product\PublicController\UProductCategoryController
     *  + user-comment: Hura8\Components\User\PublicController\UUserCommentController
     *  + user-comment-reply: Hura8\Components\User\PublicController\UUserCommentReplyController
     * */
    public static function getControllerClass(string $entity_type, $controller_type='public'): string {
        $parts = array_map(function ($word){
            return ucfirst($word);
        }, explode("-", $entity_type));

        $parent = $parts[0];

        // Hura8\Components\Product\PublicController\UProductCategoryController
        if($controller_type == 'public') {
            return "\\Hura8\\Components\\".$parent."\\PublicController\\U".join("", $parts)."Controller";
        }

        // Hura8\Components\Product\AdminController\AProductCategoryController
        return "\\Hura8\\Components\\".$parent."\\AdminController\\A".join("", $parts)."Controller";
    }


    // system's entities
    const PRODUCT                       = 'product';
    const PRODUCT_CATEGORY              = 'product-category';
    const PRODUCT_COLLECTION            = 'collection';

    const PRODUCT_ATTRIBUTE             = 'attribute';
    const PRODUCT_ATTRIBUTE_VALUE       = 'attribute-value';

    const COUPON                = 'coupon';

    const ORDER                 = 'order';

    const ARTICLE               = 'article';
    const ARTICLE_CATEGORY      = 'article-category';

    const BANNER                = 'banner';
    const BANNER_LOCATION       = 'banner-location';

    const CUSTOMER               = 'customer'; // registered customers

    const USER                   = 'user'; // all users, include customers
    const USER_CONTACT           = 'user-contact';
    const USER_COMMENT           = 'user-comment';
    const USER_COMMENT_REPLY     = 'user-comment-reply';

    const BRAND                 = 'brand';
    const DEAL                  = 'deal';
    const MEDIA                  = 'media';
    const TAG                   = 'tag';
    const URL                   = 'url';
    const COMBO_SET             = 'combo-set';

    const PAGE                  = 'page';
    const PAGE_CATEGORY         = 'page-category';

    const ALBUM                 = 'album';
    const ALBUM_CATEGORY        = 'album-category';
    const ALBUM_PHOTO           = 'album-photo';

    const PROVINCE              = 'province';

    const PROMOTION             = 'promotion';
    const PROMOTION_GROUP       = 'promotion-group';
    const DISTRIBUTOR           = 'distributor';

    const WARRANTY              = 'warranty';

    const STAFF                 = 'staff'; // admin web

    const VIDEO                 = 'video';
    const VIDEO_CATEGORY        = 'video-category';

    const JOB                 = 'job';
    const JOB_CATEGORY        = 'job-category';

    const DOMAIN              = 'domain';

}
