<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BoardGroupAdmin extends Model
{
    protected $table = 'tb_board_group_admin';
    protected $primaryKey = 'id';

    public $keyType = 'int';
    public $incrementing = true;
    public $timestamps = true;

    const CREATED_AT = 'created_at';
    const UPDATED_AT = null;

    protected $guarded = [];

    /**
     * 게시판 그룹 관리자 조회
     */
    public function data(): object
    {
        $query = $this->query();
        $query->select(
            'tb_board_group_admin.*',
            'users.sid',
            'users.name',
            'users.nickname',
            'users.email'
        );
        $query->leftJoin('users', 'users.id', '=', 'tb_board_group_admin.user_id');

        $total = $this->count();
        $rows = $query->count();
        $list = $query->get();

        return (object)[
            'total' => $total,
            'rows' => $rows,
            'list' => $list
        ];
    }
}
