package de.assecutor.votianlt.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.math.BigDecimal;

@Document(collection = "services")
public class Service {
    public static final BigDecimal FIXED_VAT_RATE = new BigDecimal("0.19");

    @Id
    private String id;

    private String userId;
    private String name;
    private CalculationBasis calculationBasis;
    private BigDecimal price; // For FLAT_RATE services
    private BigDecimal pricePerKilometer; // For DISTANCE services - price per kilometer
    private BigDecimal pricePer15Minutes; // For TIME services - price per 15 minutes
    private boolean mandatory;

    public enum CalculationBasis {
        DISTANCE, TIME, FLAT_RATE
    }

    public Service() {
    }

    public Service(String userId, String name, CalculationBasis calculationBasis, BigDecimal price,
            BigDecimal vatRate) {
        this(userId, name, calculationBasis, price, vatRate, false);
    }

    public Service(String userId, String name, CalculationBasis calculationBasis, BigDecimal price, BigDecimal vatRate,
            boolean mandatory) {
        this.userId = userId;
        this.name = name;
        this.calculationBasis = calculationBasis;
        this.mandatory = mandatory;

        // Set the appropriate price field based on calculation basis
        switch (calculationBasis) {
        case DISTANCE:
            this.pricePerKilometer = price;
            break;
        case TIME:
            this.pricePer15Minutes = price;
            break;
        case FLAT_RATE:
            this.price = price;
            break;
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public CalculationBasis getCalculationBasis() {
        return calculationBasis;
    }

    public void setCalculationBasis(CalculationBasis calculationBasis) {
        this.calculationBasis = calculationBasis;
    }

    public BigDecimal getVatRate() {
        return FIXED_VAT_RATE;
    }

    public void setVatRate(BigDecimal vatRate) {
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getPricePerKilometer() {
        return pricePerKilometer;
    }

    public void setPricePerKilometer(BigDecimal pricePerKilometer) {
        this.pricePerKilometer = pricePerKilometer;
    }

    public BigDecimal getPricePer15Minutes() {
        return pricePer15Minutes;
    }

    public void setPricePer15Minutes(BigDecimal pricePer15Minutes) {
        this.pricePer15Minutes = pricePer15Minutes;
    }

    /**
     * Get the appropriate price based on calculation basis
     */
    public BigDecimal getEffectivePrice() {
        return switch (calculationBasis) {
        case DISTANCE -> pricePerKilometer;
        case TIME -> pricePer15Minutes;
        case FLAT_RATE -> price;
        };
    }

    public boolean isMandatory() {
        return mandatory;
    }

    public void setMandatory(boolean mandatory) {
        this.mandatory = mandatory;
    }
}
