<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StoreLocation extends Model
{
    protected $fillable = [
        'name',
        'address',
        'phone',
        'email',
        'hours',
        'map_url',
        'sort_order',
        'is_active'
    ];
    
    protected $casts = [
        'is_active' => 'boolean'
    ];
    
    // Scopes
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
    
    public function scopeOrdered($query)
    {
        return $query->orderBy('sort_order')->orderBy('name');
    }
    
    // Accessors
    public function getFormattedPhoneAttribute()
    {
        return substr_replace($this->phone, '-', 5, 0);
    }
    
    public function getWhatsappLinkAttribute()
    {
        $cleanPhone = str_replace(['-', ' ', '+'], '', $this->phone);
        return 'https://wa.me/88' . $cleanPhone;
    }
}
