#include "validator.h"
#include "../exceptions/exceptions.h"

void Validator::validate_size(const std::string& size) {
    if (size.length() == 0) {
        throw ValidatorException("Invalid size!");
    }
    for(size_t i=0;i<size.length();i++){
        if(size[i]<'0' || size[i]>'9'){
            throw ValidatorException("Invalid size!");
            break;
        }
    }
    if (std::stoi(size) <= 0) {
        throw ValidatorException("Invalid size!");
    }
}

void Validator::validate_colour(const std::string& colour) {
    if (colour.length() == 0) {
        throw ValidatorException("Invalid colour!");
    }
}

void Validator::validate_price(const std::string& price) {
    if (price.length() == 0) {
        throw ValidatorException("Invalid price!");
    }
    for(size_t i=0;i<price.length();i++){
        if(price[i]<'0' || price[i]>'9'){
            throw ValidatorException("Invalid price!");
            break;
        }
    }
    if (std::stoi(price) <= 0) {
        throw ValidatorException("Invalid price!");
    }
}

void Validator::validate_quantity(const std::string& quantity) {
    if (quantity.length() == 0) {
        throw ValidatorException("Invalid quantity!");
    }
    for(size_t i=0;i<quantity.length();i++){
        if(quantity[i]<'0' || quantity[i]>'9'){
            throw ValidatorException("Invalid quantity!");
            break;
        }
    }
    if (std::stoi(quantity) < 0) {
        throw ValidatorException("Invalid quantity!");
    }
}

void Validator::validate_photograph(const std::string& photograph) {
    if (photograph.length() == 0) {
        throw ValidatorException("Invalid photograph!");
    }
}
