<?php

namespace Daylight\Core\Models;

use Daylight\Core\Models\Enums\PublishStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\Context;

class CustomerGroup extends Model
{
    protected $guarded = [];

    protected function casts(): array
    {
        return [
            'status' => PublishStatus::class,
        ];
    }

    public function customers(): BelongsToMany
    {
        return $this->belongsToMany(daylightModel('customer'))
            ->withTimestamps();
    }

    public function products(): BelongsToMany
    {
        return $this->belongsToMany(daylightModel('product'))
            ->withTimestamps();
    }

    public static function getDefault(): ?self
    {
        return Context::remember('pricing.default_customer_group', fn () => self::where('default', true)->first());
    }
}
