<?php

namespace app\admin\controller\goods;

use app\admin\service\goods\GoodsService;
use app\admin\validate\goods\GoodsValidate;
use support\Request;
use support\Response;

class RechargeGoodsController
{
    public function select(Request $request)
    {
        return GoodsService::select($request, 'RECHARGE');
    }

    public function insert(Request $request): Response
    {
        $params = $request->post();
        $validate = new GoodsValidate();
        if (!$validate->scene('add')->check($params)) {
            return json_fail($validate->getError());
        }

        return GoodsService::insertRecharge($params);
    }

    public function update(Request $request): Response
    {
        $validate = new GoodsValidate();
        if (!$validate->scene('update')->check($request->post())) {
            return json_fail($validate->getError());
        }

        return GoodsService::updateRecharge($request->post());
    }
}