<?php

namespace App\Http\Controllers\Channel\Channel;

use App\Modules\Channel\Models\PayTemplate;
use App\Modules\Channel\Services\PayTemplateService;
use Illuminate\Http\Request;
use App\Http\Controllers\Channel\BaseController;

class PayTemplateController extends BaseController
{
    public function getPayTemplate(){
        $distribution_channel_id = (int)$this->getChannelId();
        $template_id = PayTemplateService::getPayTemplate($distribution_channel_id);
        return response()->success(['type'=>$template_id]);
    }


    public function setPayTemplate(Request $request){
        $distribution_channel_id = (int)$this->getChannelId();
        $type = (int)$request->post('type');
        if(empty($type) || !in_array($type,[1,2])){
            return response()->error('PARAM_ERROR');
        }
        $res = PayTemplateService::setPayTemplate($distribution_channel_id,$type);
        return response()->success();
    }
}
