<?php

namespace App\Models;

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

class Category extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'slug',
        'description',
        'icon',
        'sort_order',
        'is_active',
        'created_by',
        'site_group',
        'site_name',
        'site_theme_color',
    ];

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
        ];
    }

    // Site group constants
    const SITE_MUSIC = 'music';
    const SITE_ART = 'art';
    const SITE_TOOLS = 'tools';

    public static function getSiteGroups()
    {
        return [
            self::SITE_MUSIC => [
                'name' => 'Music Marketplace',
                'slug' => 'music', 
                'description' => 'Buy and sell musical instruments and audio gear',
                'theme_color' => '#3B82F6',
                'domain' => 'music'
            ],
            self::SITE_ART => [
                'name' => 'Art Marketplace',
                'slug' => 'art',
                'description' => 'Buy and sell art supplies and creative tools', 
                'theme_color' => '#EF4444',
                'domain' => 'art'
            ],
            self::SITE_TOOLS => [
                'name' => 'Tools Marketplace', 
                'slug' => 'tools',
                'description' => 'Buy and sell tools and hardware',
                'theme_color' => '#10B981',
                'domain' => 'tools'
            ]
        ];
    }

    // Scope methods
    public function scopeForSite($query, $siteGroup)
    {
        return $query->where('site_group', $siteGroup);
    }

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

    public function items()
    {
        return $this->hasMany(Item::class);
    }

    public function createdBy()
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
