<?php

namespace PloverCRM\Core\CRM\Schemas;

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

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

    /**
     * Validate list 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 list data
     */
    public static function normalize(array $data): array
    {
        return [
            'id' => (int) ($data['id'] ?? 0),
            'title' => (string) ($data['title'] ?? ''),
            'slug' => (string) ($data['slug'] ?? ''),
        ];
    }
}
