<?php

declare(strict_types=1);

namespace CliqThemes\StoreLocator\Models;

defined('ABSPATH') || exit;

use CliqThemes\ORM\Model;
use CliqThemes\ORM\Relations\BelongsTo;
use CliqThemes\ORM\Relations\HasMany;

/**
 * A geocoded address for a store. The `coordinates` POINT column is a STORED
 * generated column (from latitude/longitude) and is never written directly.
 */
final class Location extends Model
{
    protected string $table = 'cliq_sl_store_locations';

    protected string $primaryKey = 'id';

    protected array $fillable = [
        'id',
        'store_id',
        'label',
        'address_line1',
        'address_line2',
        'city',
        'state',
        'postal_code',
        'country',
        'latitude',
        'longitude',
        'is_primary',
        'geocode_failed_at',
        'created_at',
        'updated_at',
    ];

    public function store(): BelongsTo
    {
        return $this->belongsTo(Store::class, 'store_id', 'id');
    }

    public function hours(): HasMany
    {
        return $this->hasMany(StoreHour::class, 'location_id', 'id');
    }
}
