<?php

namespace App\Distributor\Repositories;

use App\Models\DistAppearance as Model;
use App\Models\DistAppearanceTemplate;
use App\Models\DistAppearanceVariable;
use Carbon\Carbon;
use Dcat\Admin\Repositories\EloquentRepository;

class DistAppearance extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;


    /*
     * 切换主题操作，生成销应商主题模版与变量
     * (如果原本就有模板与变量，不会重复生成)
     */
    public static function switchTheme($appearanceId,$distId) {
        //把原始模板与变量复制给分销商
        DistAppearanceTemplate::copyTemplateToDist($appearanceId, $distId);
        DistAppearanceVariable::copyAppearanceVariable($appearanceId, $distId);
        //发报到正式环境
        DistAppearancePublishList::publish($appearanceId, $distId);
        //清除缓存
        DistAdminDistributor::clearCache();
        return true;
    }

    /*
     * 初始化分销商模版与变量
     */
    public static function initTheme($appearanceId,$distId)
    {
        //请空模版与变量
        DistAppearanceTemplate::deleteTemplates($appearanceId,$distId);
        DistAppearanceVariable::deleteVariable($appearanceId, $distId);
        //重新生成模版与变量
        self::switchTheme($appearanceId, $distId);
    }
}
