#include "bindings.hpp"

void init_data_validation(py::module_& m) {
    // Bind XLDataValidationConfig
    py::class_<XLDataValidationConfig>(m, "XLDataValidationConfig")
        .def(py::init<>())
        .def_rw("type", &XLDataValidationConfig::type)
        .def_rw("operator_", &XLDataValidationConfig::operator_)
        .def_rw("allow_blank", &XLDataValidationConfig::allowBlank)
        .def_rw("show_drop_down", &XLDataValidationConfig::showDropDown)
        .def_rw("show_input_message", &XLDataValidationConfig::showInputMessage)
        .def_rw("show_error_message", &XLDataValidationConfig::showErrorMessage)
        .def_rw("ime_mode", &XLDataValidationConfig::imeMode)
        .def_rw("error_style", &XLDataValidationConfig::errorStyle)
        .def_rw("prompt_title", &XLDataValidationConfig::promptTitle)
        .def_rw("prompt", &XLDataValidationConfig::prompt)
        .def_rw("error_title", &XLDataValidationConfig::errorTitle)
        .def_rw("error", &XLDataValidationConfig::error)
        .def_rw("formula1", &XLDataValidationConfig::formula1)
        .def_rw("formula2", &XLDataValidationConfig::formula2);

    // Bind XLDataValidation
    py::class_<XLDataValidation>(m, "XLDataValidation")
        .def(py::init<>())
        .def("empty", &XLDataValidation::empty)
        .def("sqref", &XLDataValidation::sqref)
        .def("type", &XLDataValidation::type)
        .def("operator_", &XLDataValidation::operator_)
        .def("allow_blank", &XLDataValidation::allowBlank)
        .def("formula1", &XLDataValidation::formula1)
        .def("formula2", &XLDataValidation::formula2)
        .def("show_drop_down", &XLDataValidation::showDropDown)
        .def("show_input_message", &XLDataValidation::showInputMessage)
        .def("show_error_message", &XLDataValidation::showErrorMessage)
        .def("ime_mode", &XLDataValidation::imeMode)
        .def("prompt_title", &XLDataValidation::promptTitle)
        .def("prompt", &XLDataValidation::prompt)
        .def("error_title", &XLDataValidation::errorTitle)
        .def("error", &XLDataValidation::error)
        .def("error_style", &XLDataValidation::errorStyle)
        .def("config", &XLDataValidation::config)
        .def("apply_config", &XLDataValidation::applyConfig)
        .def("set_sqref", &XLDataValidation::setSqref)
        .def("add_cell", py::overload_cast<const XLCellReference&>(&XLDataValidation::addCell))
        .def("add_cell", py::overload_cast<const std::string&>(&XLDataValidation::addCell))
        .def("add_range", py::overload_cast<const XLCellReference&, const XLCellReference&>(&XLDataValidation::addRange))
        .def("add_range", py::overload_cast<const std::string&>(&XLDataValidation::addRange))
        .def("remove_cell", py::overload_cast<const XLCellReference&>(&XLDataValidation::removeCell))
        .def("remove_cell", py::overload_cast<const std::string&>(&XLDataValidation::removeCell))
        .def("remove_range", py::overload_cast<const XLCellReference&, const XLCellReference&>(&XLDataValidation::removeRange))
        .def("remove_range", py::overload_cast<const std::string&>(&XLDataValidation::removeRange))
        .def("set_type", &XLDataValidation::setType)
        .def("set_operator", &XLDataValidation::setOperator)
        .def("set_allow_blank", &XLDataValidation::setAllowBlank)
        .def("set_formula1", &XLDataValidation::setFormula1)
        .def("set_formula2", &XLDataValidation::setFormula2)
        .def("set_prompt", &XLDataValidation::setPrompt)
        .def("set_error", &XLDataValidation::setError, py::arg("title"), py::arg("msg"), py::arg("style") = XLDataValidationErrorStyle::Stop)
        .def("set_show_drop_down", &XLDataValidation::setShowDropDown)
        .def("set_show_input_message", &XLDataValidation::setShowInputMessage)
        .def("set_show_error_message", &XLDataValidation::setShowErrorMessage)
        .def("set_ime_mode", &XLDataValidation::setIMEMode)
        .def("set_whole_number_range", &XLDataValidation::setWholeNumberRange)
        .def("set_decimal_range", &XLDataValidation::setDecimalRange)
        .def("set_date_range", &XLDataValidation::setDateRange)
        .def("set_time_range", &XLDataValidation::setTimeRange)
        .def("set_text_length_range", &XLDataValidation::setTextLengthRange)
        .def("set_list", &XLDataValidation::setList)
        .def("set_reference_drop_list", &XLDataValidation::setReferenceDropList);

    // Bind XLDataValidations
    py::class_<XLDataValidations>(m, "XLDataValidations")
        .def("empty", &XLDataValidations::empty)
        .def("count", &XLDataValidations::count)
        .def("append", &XLDataValidations::append)
        .def("add_validation", &XLDataValidations::addValidation)
        .def("at", py::overload_cast<size_t>(&XLDataValidations::at))
        .def("at", py::overload_cast<std::string_view>(&XLDataValidations::at))
        .def("clear", &XLDataValidations::clear)
        .def("remove", py::overload_cast<size_t>(&XLDataValidations::remove))
        .def("remove", py::overload_cast<std::string_view>(&XLDataValidations::remove))
        .def("disable_prompts", &XLDataValidations::disablePrompts)
        .def("set_disable_prompts", &XLDataValidations::setDisablePrompts)
        .def("x_window", &XLDataValidations::xWindow)
        .def("set_x_window", &XLDataValidations::setXWindow)
        .def("y_window", &XLDataValidations::yWindow)
        .def("set_y_window", &XLDataValidations::setYWindow)
        .def("__iter__", [](const XLDataValidations& self) {
            return py::make_iterator(py::type<XLDataValidations>(), "Iterator", self.begin(), self.end());
        }, py::keep_alive<0, 1>());
}
