<?php

namespace Modules\Channel\Http\Controllers;

use Catch\Base\CatchController;
use Illuminate\Http\Request;
use Log;
use Modules\Channel\Models\UserHasMiniprograms;
use Modules\User\Models\User;

class UserMiniprogramController extends CatchController
{
    public function __construct(
        protected readonly User $user,
        protected readonly UserHasMiniprograms $userHasMiniprograms
    ) {
    }

    public function index(Request $request)
    {
        $uid = $this->getLoginUser()->id;
        Log::info('channel',['c'=>'UserMiniprogramController','uid'=>$uid]);
        return $this->userHasMiniprograms->join('miniprogram','miniprogram.id','=','user_has_miniprograms.miniprogram_id')
        ->where('user_has_miniprograms.is_enabled',1)
        ->where('uid',$uid)
        ->select('user_has_miniprograms.miniprogram_id','miniprogram.name','miniprogram.play_name')
        ->get();
    }
}
