package de.assecutor.votianlt.model;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "cargo_items")
public class CargoItem {
    @Id
    @JsonIgnore
    private ObjectId id;

    @Field("job_id")
    private ObjectId jobId;

    @Field("description")
    private String description;

    @Field("quantity")
    private Integer quantity;

    @Field("weight_kg")
    private Double weightKg;

    @Field("length_mm")
    private Double lengthMm;

    @Field("width_mm")
    private Double widthMm;

    @Field("height_mm")
    private Double heightMm;

    /**
     * Returns the ObjectId as string for JSON serialization. This ensures that the
     * cargo item id is returned as a string when items are retrieved via API.
     */
    @JsonGetter("id")
    public String getIdAsString() {
        return id != null ? id.toString() : null;
    }
}
