<?php

namespace App\Http\Controllers\Admin\Syj;

use App\Models\Syj\GroupModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class GroupController extends Controller
{
    //
    public function index()
    {
        $groups = GroupModel::get();
        return response([
            'code' => 200,
            'message' => 'OK',
            'data' => $groups
        ]);
    }


    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required',
            'image' => 'required',
            'capacity_number' => 'required|integer',
            'total_number' => 'integer|integer',
            'expired_at' => 'required|integer',
            'state' => 'integer',
        ]);
        $group = GroupModel::create($request->all());
        return response([
            'code' => 200,
            'message' => 'OK',
            'data' => $group
        ]);
    }

    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'name' => '',
            'image' => '',
            'capacity_number' => 'integer',
            'total_number' => 'integer',
            'expired_at' => 'integer',
            'state' => 'integer',
        ]);
        $group = GroupModel::findOrFail($id);
        $group->update($request->all());
        return response([
            'code' => 200,
            'message' => 'Success',
            'data' => $group
        ]);
    }
}
