<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory;
    protected $casts = [
        'user_id' => 'integer',
        'latitude' => 'float',
        'longitude' => 'float',
        'place_id' => 'integer',
        'google_place_name' => 'string',
        'google_place_id' => 'string',
        'google_place_url' => 'string',
        'google_place_address' => 'string',
        'description' => 'string',
        'province_id' => 'integer',
        'like_count' => 'integer',
        'comment_count' => 'integer',
        'language_code' => 'string',
        'enable_comment' => 'boolean',
        'is_public' => 'boolean',
        'active' => 'boolean',
        'is_liked' => 'boolean',
    ];

    protected $fillable = [
        'user_id',
        'latitude',
        'longitude',
        'place_id',
        'google_place_name',
        'google_place_id',
        'google_place_url',
        'google_place_address',
        'description',
        'province_id',
        'like_count',
        'comment_count',
        'language_code',
        'enable_comment',
        'is_public',
        'status',
    ];

/*     protected $appends = ['is_liked'];

    public function getIsLikedAttribute() //is_admin is the function
    {
        return false;
    } */

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }

    public function province()
    {
        return $this->hasOne(Province::class, 'id', 'province_id');
    }

    public function place()
    {
        return $this->hasOne(Place::class, 'id', 'place_id');
    }

    public function images()
    {
        return $this->hasMany(PostImage::class, 'post_id', 'id')->select('id','image_url','description');
    }

    public function likes(){
        return $this->hasMany(PostLike::class, 'post_id', 'id');
    }

    public function comments(){
        return $this->hasMany(PostComment::class, 'post_id', 'id');
    }
}
