/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;

import static de.srsoftware.umbrella.core.ModuleRegistry.stockService;
import static de.srsoftware.umbrella.core.constants.Field.ID;
import static de.srsoftware.umbrella.core.constants.Field.LOCATION_ID;
import static java.text.MessageFormat.format;

import de.srsoftware.tools.Mappable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class Location implements Mappable {

	private long id;

	public Location(long id){
		this.id = id;
	}

	public long id(){
		return id;
	}

	public <T extends Location> T id(long newValue){
		id = newValue;
		//noinspection unchecked
		return (T) this;
	}

	public static Location of(ResultSet rs) throws SQLException {
		return new Location(rs.getLong(LOCATION_ID));
	}

	public static Location of(long locationId) {
		return new Location(locationId);
	}

	public DbLocation resolve(){
		return stockService().loadLocation(id());
	}

	@Override
	public Map<String, Object> toMap() {
		var map = new HashMap<String,Object>();
		map.put(ID,id);
		return map;
	}

	@Override
	public String toString() {
		return format("Location({0})",id);
	}
}
