<?php

declare(strict_types=1);

namespace CliqThemes\StoreLocator\Models;

defined('ABSPATH') || exit;

use CliqThemes\ORM\Model;
use CliqThemes\ORM\Relations\BelongsToMany;
use CliqThemes\ORM\Relations\HasMany;
use CliqThemes\ORM\Relations\HasOne;

final class Store extends Model
{
    protected string $table = 'cliq_sl_stores';

    protected string $primaryKey = 'id';

    protected bool $softDeletes = true;

    protected array $fillable = [
        'id',
        'name',
        'slug',
        'description',
        'status',
        'featured',
        'ordering',
        'lang',
        'trid',
        'source_id',
        'phone',
        'email',
        'website',
        'rating',
        'rating_count',
        'city',
        'country',
        'logo_id',
        'marker_id',
        'marker_design_id',
        'marker_source',
        'owner_id',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    /**
     * All geocoded locations belonging to the store.
     */
    public function locations(): HasMany
    {
        return $this->hasMany(Location::class, 'store_id', 'id');
    }

    /**
     * The primary location used for listings and single-store display.
     */
    public function primaryLocation(): HasOne
    {
        return $this->hasOne(Location::class, 'store_id', 'id');
    }

    /**
     * Categories assigned to the store (many-to-many).
     */
    public function categories(): BelongsToMany
    {
        return $this->belongsToMany(Category::class, 'cliq_sl_store_category', 'store_id', 'category_id');
    }

    /**
     * Brands associated with the store (many-to-many).
     */
    public function brands(): BelongsToMany
    {
        return $this->belongsToMany(Brand::class, 'cliq_sl_brand_store', 'store_id', 'brand_id');
    }
}
