<?php

namespace App\Http\Controllers\Wechat\OfficialAccount;

use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
use App\Modules\OfficialAccount\Services\CustomSendStatsService;
use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomSendStatsTransformers;
use Illuminate\Http\Request;

class CustomSendStatsController extends ChannelBaseController
{

     /**
     * @apiDefine OfficialAccount 公众号
     */

    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/customSendDayStatsByChannelAndFrom 获取每日智能推送分析数据
     * @apiGroup OfficialAccount
     * @apiName customSendDayStatsByChannelAndFrom
     * @apiSuccessExample {json} Success-Response:
     *
     *      {
     *          "code": 0,
     *          "msg": "",
     *          "data": [
     *              
     *          ]
     *      }
     */
    function  customSendDayStatsByChannelAndFrom(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");
        }

        $from = $request->has('from') ? $request->input('from') : '';
        if(empty($from)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomSendStatsService::customSendDayStatsByChannelAndFrom($distribution_channel_id,$from);

        if (!empty($customMsgService)) {
            
            return response()->pagination(new CustomSendStatsTransformers(), $customMsgService);
        }else{

            return response()->success(['data'=>0]);
        }
        
    }

    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/customSendStatsByChannelAndFrom 获取渠道下智能推送分析总数据
     * @apiGroup OfficialAccount
     * @apiName customSendStatsByChannelAndFrom
     * @apiSuccessExample {json} Success-Response:
     *
     *      {
     *          "code": 0,
     *          "msg": "",
     *          "data": [
     *              
     *          ]
     *      }
     */
    function  customSendStatsByChannelAndFrom(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");
        }

        $from = $request->has('from') ? $request->input('from') : '';
        if(empty($from)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomSendStatsService::customSendStatsByChannelAndFrom($distribution_channel_id,$from);

        if (!empty($customMsgService)) {
            
            return response()->item(new CustomSendStatsTransformers(), $customMsgService);
        }else{

            return response()->success(['data'=>0]);
        }
        
    }


    
}