<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Store extends BaseModel
{
    protected $table = 'stores';

    protected $fillable = ['id', 'package_id', 'area_id', 'station_id', 'name', 'slug', 'address', 'phone_number', 'email',
                           'title', 'description', 'other_request', 'open_time', 'working_time', 'latitude', 'longitude',
                           'near', 'rating', 'thumbnail', 'origin_thumb', 'website', 'original_link', 'refer_id',
                           'seo_title', 'seo_robots', 'seo_keywords', 'seo_description', 'is_amp',
                           'is_activated', 'is_deleted', 'created_at', 'updated_at'];

    public function package() {
        return $this->belongsTo(Package::class, 'package_id', 'id');
    }

    public function area() {
        return $this->belongsTo(Area::class, 'area_id', 'id')->with('parent');
    }

    public function station() {
        return $this->belongsTo(Station::class, 'station_id', 'id');
    }

    public function seo() {
        return $this->belongsTo(Seo::class, 'id', 'post_id')->select('id', 'post_id', 'title', 'robots', 'keywords', 'description', 'image', 'uri', 'type', 'is_amp')->where('type', 'store');
    }

    public function comment() {
        return $this->hasMany(StoreComment::class, 'store_id', 'id')->select('id', 'store_id', 'author', 'rate', 'content', 'image', 'created_at')->where('is_deleted', false)->where('is_activated', true);
    }

    public function brand_detail() {
        return $this->hasMany(BrandDetail::class, 'store_id', 'id')->with('brand')->select('id', 'store_id', 'brand_id');
    }
}
