package org.example.petshopdesktop.DTOs;

import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import org.example.petshopdesktop.models.Product;

/**
 * The class for productDTO, all product data is store here but also gets categoryName
 */
public class ProductDTO {
    private SimpleIntegerProperty prodId;
    private SimpleStringProperty prodName;
    private SimpleDoubleProperty prodPrice;
    private SimpleIntegerProperty categoryId; //used for edit and delete
    private SimpleStringProperty categoryName;
    private SimpleStringProperty prodDesc;
    private SimpleStringProperty imageUrl;

    //constructor
    public ProductDTO(int prodId, String prodName, double prodPrice, int categoryId, String categoryName, String prodDesc, String imageUrl) {
        this.prodId = new SimpleIntegerProperty(prodId);
        this.prodName = new SimpleStringProperty(prodName);
        this.prodPrice = new SimpleDoubleProperty(prodPrice);
        this.categoryId = new SimpleIntegerProperty(categoryId);
        this.categoryName = new SimpleStringProperty(categoryName);
        this.prodDesc = new SimpleStringProperty(prodDesc);
        this.imageUrl = new SimpleStringProperty(imageUrl);
    }

    //getter and setters
    public int getProdId() {
        return prodId.get();
    }

    public SimpleIntegerProperty prodIdProperty() {
        return prodId;
    }

    public void setProdId(int prodId) {
        this.prodId.set(prodId);
    }

    public String getProdName() {
        return prodName.get();
    }

    public SimpleStringProperty prodNameProperty() {
        return prodName;
    }

    public void setProdName(String prodName) {
        this.prodName.set(prodName);
    }

    public double getProdPrice() {
        return prodPrice.get();
    }

    public SimpleDoubleProperty prodPriceProperty() {
        return prodPrice;
    }

    public void setProdPrice(double prodPrice) {
        this.prodPrice.set(prodPrice);
    }

    public String getCategoryName() {
        return categoryName.get();
    }

    public SimpleStringProperty categoryNameProperty() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName.set(categoryName);
    }

    public String getProdDesc() {
        return prodDesc.get();
    }

    public SimpleStringProperty prodDescProperty() {
        return prodDesc;
    }

    public void setProdDesc(String prodDesc) {
        this.prodDesc.set(prodDesc);
    }

    public int getCategoryId() {
        return categoryId.get();
    }

    public SimpleIntegerProperty categoryIdProperty() {
        return categoryId;
    }

    public void setCategoryId(int categoryId) {
        this.categoryId.set(categoryId);
    }

    public String getImageUrl() {
        return imageUrl.get();
    }

    public SimpleStringProperty imageUrlProperty() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl.set(imageUrl);
    }

    /**
     * Converts DTO into product for editing and deleting
     * @return
     */
    public Product toProduct(){
        Product product = new Product(
                getProdId(),
                getProdName(),
                getProdPrice(),
                getCategoryId(),
                getProdDesc()
        );
        return product;
    }
}
