<?php

namespace PloverCRM\Core\CRM\Schemas;

/**
 * Tag Schema
 * 
 * Defines the standard structure for tag data across all CRM providers
 */
class TagSchema
{
    /**
     * Required fields
     */
    const REQUIRED_FIELDS = ['id', 'title'];

    /**
     * All fields with their types
     */
    const FIELDS = [
        'id' => 'integer',
        'title' => 'string',
        'slug' => 'string',
    ];

    /**
     * Validate tag data
     */
    public static function validate(array $data): array
    {
        $errors = [];

        foreach (self::REQUIRED_FIELDS as $field) {
            if (!isset($data[$field]) || $data[$field] === null || $data[$field] === '') {
                $errors[] = "Required field '{$field}' is missing or empty";
            }
        }

        return [
            'valid' => empty($errors),
            'errors' => $errors,
        ];
    }

    /**
     * Normalize tag data
     */
    public static function normalize(array $data): array
    {
        return [
            'id' => (int) ($data['id'] ?? 0),
            'title' => (string) ($data['title'] ?? ''),
            'slug' => (string) ($data['slug'] ?? ''),
        ];
    }
}
