<?php
namespace App\Models;

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
/**
 * Description of SeoKeyword
 *
 * @author Phattharaphon
 */
class SeoKeywordUrlRel extends Authenticatable  {
    use HasFactory, Notifiable;

    protected $table = 'seo_keyword_url_rel'; // Set custom table name
    protected $primaryKey = 'seoKeywordUrlRelID';  // varchar primary key
    public $incrementing = false;
    protected $keyType = 'string';
    protected $fillable = ['seoKeywordUrlRelID', 'seoKeywordID', 'seoWebsiteCode', 'seoRelFlg', 'accountCode', 'status_flg', 'automatic_tracking_status']; // Add more fields if needed
    //

    public static function GetWebUrlRelByAccountCode($accountCode=null, $seoKeywordID=null)
    {
        $return = false;
        if($accountCode !== null && $seoKeywordID === null){
            $return = DB::table('seo_keyword_url_rel as url_rel')
                    ->leftJoin('websites', 'url_rel.seoWebsiteCode', '=', 'websites.websiteCode')
                    ->where('url_rel.accountCode', $accountCode)
                    ->select(
                        'websites.domain'
                    )
                    ->groupBy('websites.websiteCode', 'websites.domain')
                    ->get()->toArray();
        }else if($accountCode !== null && $seoKeywordID !== null){
            $return = DB::table('seo_keyword_url_rel as url_rel')
                    ->leftJoin('websites', 'url_rel.seoWebsiteCode', '=', 'websites.websiteCode')
                    ->where('url_rel.accountCode', $accountCode)
                    ->where('url_rel.seoKeywordID', $seoKeywordID)
                    ->select(
                        'websites.domain'
                    )
                    ->groupBy('websites.websiteCode', 'websites.domain')
                    ->get()->toArray();
            
        }
        return $return;
    }
    
    public static function SaveWebsiteKeywordRel(Request $request, $keywordID=null)
    {

        
    }//SaveWebsiteKeywordRel
    
    
    
}//end class SeoKeywordUrlRel
