<?php

namespace App\Http\Controllers\Manage\OfficialAccount;

use App\Http\Controllers\Channel\BaseController;
use App\Modules\OfficialAccount\Services\OfficialAccountService;
use App\Http\Controllers\Manage\OfficialAccount\Transformers\OfficialAccountTransformer;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
use App\Libs\OSS;

class OfficialAccountsController extends BaseController
{


    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/allOfficialAccountBydistributionChannelId 根据分销渠道号获取服务号列表
     * @apiGroup OfficialAccount
     * @apiName allOfficialAccountBydistributionChannelId
     * @apiParam   {String}  distribution_channel_id 分销渠道id. 
     * @apiSuccess {String}  name 公众号原始名称.
     * @apiSuccess {String}  nickname 公众号名称.
     * @apiSuccess {String}  alias 唯一ID.
     * @apiSuccess {String}  qrcode_url 二维码地址.
     * @apiSuccess {String}  principal_name 公司名称.
     * @apiSuccess {String}  func_info 功能信息.
     * @apiSuccess {String}  head_img 头像地址.
     * @apiSuccess {String}  appid 微信appID.
     * @apiSuccess {String}  appsecret 微信appsecret.
     * @apiSuccess {String}  verify_txt 验证文件.
     * @apiSuccess {String}  verify_type_info 授权方认证类型.
     * @apiSuccess {String}  authorizer_refresh_token 授权的刷新token.
     * @apiSuccess {String}  cancel_auth_time 取消授权时间.
     * @apiSuccess {String}  official_account_type 第三方平台关注公众号.
     * @apiSuccess {Number}  is_auth 是否授权.
     * @apiSuccess {String}  service_type_info 服务号类型.
     * @apiSuccess {Number}  subscribe_top_num 强制关注总额.
     * @apiSuccess {Number}  subscribe_day_maximum 强制关注日限额.
     * @apiSuccess {Number}  todayForceSubscribeUsers 今日关注总数.
     * @apiSuccess {Number}  allForceSubscribeUsers 关注总数.
     * @apiSuccess {Number}  is_enabled 是否可用.
     * @apiSuccessExample {json} Success-Response:
     *
     *     {
     *       "code": 0,
     *       "msg": "",
     *       "data": {
     *           {
     *              "name": "测试呵呵",
     *              "nickname": "大哥",
     *              "alias": "23534dsgdsvdx",
     *              "head_img": "www.baidu.com",
     *              "appid": "1211",
     *              "appsecret": "dsfsdf3452352",
     *              "verify_txt": null,
     *              "is_auth": 1,
     *              "service_type_info": "546dsfwr23r",
     *              "subscribe_top_num": null,
     *              "subscribe_day_maximum": null,
     *              "distribution_channel_id": 1,
     *              "qrcode_url": "fdhgfds435gsdfg43t",
     *              "principal_name": "dfgh435saf2332",
     *              "func_info": "ry3t342trwe",
     *              "authorizer_refresh_token": "4534dfsgdsgsdgsdg",
     *              "cancel_auth_time": null,
     *              "official_account_type": "32dfaw234yewf",
     *              "verify_type_info": null,
     *              "is_enabled": 1,
     *              "todayForceSubscribeUsers": 0,
     *              "allForceSubscribeUsers": 0
     *          }
     *       }
     *      }
     */

    function allOfficialAccountBydistributionChannelId(Request $request)
    {

        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';

        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        \Log::info('-------------------获取当前渠道下的所有服务号-----------------------------------');
        \Log::info($distribution_channel_id);

        $officialAccount['distribution_channel_id'] = $distribution_channel_id;

        $officialAccountService = OfficialAccountService::allOfficialAccountBydistributionChannelId($officialAccount);
        
        return response()->collection(new OfficialAccountTransformer(), $officialAccountService);
    }


    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/officialAccountCountByChannelId 通过渠道Id获取公众号数量
     * @apiGroup OfficialAccount
     * @apiName officialAccountCountByChannelId
     * @apiParam   {String}  distribution_channel_id 分销渠道id. 
     * @apiSuccess {Number}  official_num 公众号数量.
     * @apiSuccessExample {json} Success-Response:
     *
     *     {
     *       "code": 0,
     *       "msg": "",
     *       "data": {
     *           "official_num": 2,
     *       }
     *      }
     */

    function officialAccountCountByChannelId(Request $request)
    {

        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';

        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $officialAccount['distribution_channel_id'] = $distribution_channel_id;
        $officialAccountService = OfficialAccountService::officialAccountCountByChannelId($officialAccount);
        return response()->success(['official_num'=>$officialAccountService]);
    }

    
}