<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BoardAdmin extends Model
{
    protected $table = 'tb_board_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_admin.*',
            'users.sid',
            'users.name',
            'users.nickname',
            'users.email'
        );

        $query->join('users', 'users.id', '=', 'tb_board_admin.user_id');

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

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