<?php

namespace Server\Controllers\Validators;

class TradesValidator extends ApiValidator
{

    public function apiCreate($body) {

        if ($body['amount'] == 0) {
            return ['amount must be greater than zero'];
        }

        if (!isset($body['chart'])) {
            return ['chart is required'];
        }

        return [];
    }

    public function apiUpdate($body)
    {
        $errors = [];

        $id = $body['id'] ?? '';
        $closing_price = $body['closing_price'] ?? '';

        if (!is_numeric($id)) {
            array_push($errors, "id must be a number");
        }

        if (!is_numeric($closing_price)) {
            array_push($errors, "closing price must be a number");
        }

        return $errors;
    }
}
