<?php
/**
 * Created by PhpStorm.
 * User: ywl
 * Date: 2017/4/14
 * Time: 10:56
 */

namespace App\Common\Providers;

use App\Common\Facades\ComEmailCodeFacade;
use App\Common\Facades\ComSmsFacade;
use App\Common\Facades\OssFacade;
use App\Common\Facades\PinYinFacade;
use App\Common\Facades\UploadFileFacade;
use App\Common\Facades\UserCenterFacade;
use App\Common\Models\ComEmailCodeModel;
use App\Common\Models\ComOssETagModel;
use App\Common\Models\ComSmsModel;
use App\Common\Services\ComEmailCodeService;
use App\Common\Services\ComSmsService;
use App\Common\Services\OssService;
use App\Common\Services\PinYinService;
use App\Common\Services\UploadFileService;
use App\Common\Services\UserCenterService;
use App\Providers\EventServiceProvider;

class CommonProvider extends EventServiceProvider
{

    /**
     * 注册绑定门面
     */
    public function register()
    {
        //注册上传接口
        $this->registerUpload();
        //OSS
        $this->registerOss();
        //注册公共短信服务
        $this->registerComSms();
        //注册短信验证码
        $this->registerComEmailCode();
        //注册用户中心服务
        $this->registerUserCenter();

        $this->registerPinYin();
    }

    /**
     * 注册OSS
     */
    protected function registerOss(){

        $this->app->bind(OssService::class, function () {
            return new OssService(new ComOssETagModel());
        });
        $this->app->bind(OssFacade::class, function () {
            return app()->make(OssService::class);
        });
    }

    /**
     * 注册OSS
     */
    protected function registerUpload(){
        $this->app->bind(UploadFileFacade::class, function () {
            return app()->make(UploadFileService::class);
        });
    }

    /**
     * 注册公共短信验证码发送服务
     * */
    protected function registerComSms(){
        $this->app->bind(ComSmsService::class, function () {
            return new ComSmsService(new ComSmsModel());
        });
        $this->app->bind(ComSmsFacade::class, function () {
            return app()->make(ComSmsService::class);
        });
    }

    /**
     * 注册公共邮箱验证码发送服务
     * */
    protected function registerComEmailCode()
    {
        $this->app->bind(ComEmailCodeService::class, function () {
            return new ComEmailCodeService(new ComEmailCodeModel());
        });
        $this->app->bind(ComEmailCodeFacade::class, function () {
            return app()->make(ComEmailCodeService::class);
        });
    }

    protected function registerUserCenter()
    {
        $this->app->bind(UserCenterFacade::class, function () {
            return app()->make(UserCenterService::class);
        });
    }

    /**
     * 拼音
     */
    protected function registerPinYin()
    {
        $this->app->bind(PinYinFacade::class, function () {
            return app()->make(PinYinService::class);
        });
    }

}
