<?php

namespace App\Models;

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

/**
 * @mixin IdeHelperConsultantProfile
 */
class ConsultantProfile extends Model
{
    use HasFactory;

    
    public const STATUS_PENDING = 'pending';
    public const STATUS_APPROVED = 'approved';
    public const STATUS_REJECTED = 'rejected';

    
    public const AGENT_PERMISSION_KEYS = [
        'listing.view',
        'listing.create',
        'listing.update.own',
        'listing.delete.own',
        'consultant.profile.update.own',
    ];

    protected $fillable = [
        'user_id',
        'company_name',
        'slug',
        'phone',
        'whatsapp_phone',
        'bio',
        'profile_image',
        'cover_image',
        'city',
        'district',
        'address',
        'license_number',
        'website_url',
        'instagram_url',
        'linkedin_url',
        'is_verified',
        'verified_at',
        'is_active',
        'application_status',
        'rejection_reason',
        'applied_at',
        'company_id'
    ];

    protected $casts = [
        'is_verified' => 'boolean',
        'is_active' => 'boolean',
        'verified_at' => 'datetime',
        'applied_at' => 'datetime',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function company()
    {
        return $this->belongsTo(Company::class);
    }

    public function listings()
    {
        return $this->hasMany(Listing::class);
    }

    public function conversations()
    {
        return $this->hasMany(Conversation::class);
    } 

    public function subscriptions()
    {
        return $this->morphMany(
            ProfileSubscriptions::class,
            'subscribable'
        );
    }

    public function comments()
    {
        return $this->hasMany(Comment::class, 'consultant_id');
    }



    public function scopeActive($query)
    {
        return $query->where('is_active',true);
    }
}