<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace Applications\sample\modules\category\validate\domain;
use app\validate\domain\DomainValidatorInterface;
/**
 * Category Domain Validator
 * @package Applications\sample\modules\category\validate\domain
 */
class CategoryDomainValidator implements DomainValidatorInterface
{
    /**
     * 验证分类数据
     * @param array $data 待验证数据
     * @param string $scene 验证场景
     * @return array
     */
    public function validate(array $data, string $scene = ''): array
    {
        $errors = [];
        if ($scene === 'save' || $scene === 'create') {
            if (empty($data['name'])) {
                $errors['name'] = '分类名称不能为空';
            }
        }
        if ($scene === 'delete') {
            if (empty($data['id'])) {
                $errors['id'] = '分类ID不能为空';
            }
        }
        return ['ok' => empty($errors), 'errors' => $errors];
    }
}
