<?php

namespace App\Http\Services\Web;

use App\Models\SignupData;
use App\Models\TrackData;

use DB;
use GuzzleHttp\Client;

class SeminarSignUpService
{
    protected $signupDb;
    protected $trackDataDb;
    
    public function __construct()
    {
        $this->signupDb = new SignupData();
        $this->trackDataDb = new TrackData();
        
    }
    
    public function insertData($name, $email, $mobile, $trackNo)
    {
        
        $this->signupDb
            ->insert([
                'name' => $name,
                'email' => $email,
                'mobile' => $mobile,
                'trackNo' => $trackNo,
                'createDate' => date("Y-m-d H:i:s"),
            ]);
        
    }
    
    public function overLimitOrNot($trackNo)
    {
        $nowCount = $this->signupDb
            ->where('trackNo', '=', $trackNo)
            ->count();
        
        $limit = $this->trackDataDb
            ->select('trackLimit')
            ->where('trackNo', '=', $trackNo)
            ->first();
        
        if ($limit->trackLimit>$nowCount) {
            return true;
        } else {
            return false;
        }
    }
    
    public function getData()
    {
        $res = $this->trackDataDb
        ->select([
            '*'
        ])
        ->get();

        // 整理返回值並返回
        return $res;

    }

}